Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 104
Default Using the Dictionary object

Hi we have a form with a next and prev buttons we are using the dictionary
object to hold the answers selected by the user, we use the check box
selection for each question selected if the check is true we add it to the
dictionary and if unticked we remove it from the dictionary then the use
would move to the next set of question that are loaded from a database. If
the use uses the prev button and the data is loaded from the database and the
check boxes are ticked from the dictionary, if the user unticks a check box
the code tries to remove this refference from then dictionary when we use the
exist it finds it but wont remove it? can any body explain reason for this.
TIA
Charles
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Using the Dictionary object

show the code that doesn't work.

--
Regards,
Tom Ogilvy


"vqthomf" wrote:

Hi we have a form with a next and prev buttons we are using the dictionary
object to hold the answers selected by the user, we use the check box
selection for each question selected if the check is true we add it to the
dictionary and if unticked we remove it from the dictionary then the use
would move to the next set of question that are loaded from a database. If
the use uses the prev button and the data is loaded from the database and the
check boxes are ticked from the dictionary, if the user unticks a check box
the code tries to remove this refference from then dictionary when we use the
exist it finds it but wont remove it? can any body explain reason for this.
TIA
Charles

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 104
Default Using the Dictionary object

The code for selecting the check box is
Private Sub LV_ItemCheck(ByVal Item As MSComctlLib.ListItem)
'

RcdNumber = Item.Index

Select Case Item.Checked
Case True
dct.Add LV.ListItems(RcdNumber), " "
Debug.Print "Added " & LV.ListItems(RcdNumber)
TextBox1.Text = ""
TextBox1.SetFocus
Case False
If dct.Exists(LV.ListItems(RcdNumber)) Then dct.Remove
(LV.ListItems(RcdNumber))
LV.ListItems(RcdNumber).SubItems(3) = ""
TextBox1.Text = ""
End Select

End Sub

This works as long as you are working on the listbox move away it wont
remove an item.

Private Sub cmdPrev_Click()
'
Dim itm, litm, strKey As String, i

If cmdNext.Enabled = False Then cmdNext.Enabled = True
MyNext = MyNext - 1
MyLabelNum = MyNext
MyLabelNum = LabelConfig(MyLabelNum)
If MyNext < 2 Then cmdPrev.Enabled = False
LV.ListItems.Clear
Call GetQuest

For i = 0 To dct.Count - 1
itm = dct.Keys(i)
For Each litm In LV.ListItems
If litm = itm Then
LV.ListItems(litm.Index).Checked = True
LV.ListItems(litm.Index).SubItems(3) =
dct.Item(dct.Keys(i))
End If
Next litm
Next i

'Call GetSavedData
End Sub
this will bring back everything including items that we thought had been
removed.

"Tom Ogilvy" wrote:

show the code that doesn't work.

--
Regards,
Tom Ogilvy


"vqthomf" wrote:

Hi we have a form with a next and prev buttons we are using the dictionary
object to hold the answers selected by the user, we use the check box
selection for each question selected if the check is true we add it to the
dictionary and if unticked we remove it from the dictionary then the use
would move to the next set of question that are loaded from a database. If
the use uses the prev button and the data is loaded from the database and the
check boxes are ticked from the dictionary, if the user unticks a check box
the code tries to remove this refference from then dictionary when we use the
exist it finds it but wont remove it? can any body explain reason for this.
TIA
Charles

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Using the Dictionary object

I get an error if I use the construct of

itm = dct.Keys(i)

So maybe you have an error handler clouding the issue.

I would use


Private Sub cmdPrev_Click()
'
Dim itm, litm, strKey As String, i, a

If cmdNext.Enabled = False Then cmdNext.Enabled = True
MyNext = MyNext - 1
MyLabelNum = MyNext
MyLabelNum = LabelConfig(MyLabelNum)
If MyNext < 2 Then cmdPrev.Enabled = False
LV.ListItems.Clear
Call GetQuest

a = dct.Keys
For i = 0 To dct.Count - 1
itm = a(i)
For Each litm In LV.ListItems
If litm = itm Then
LV.ListItems(litm.Index).Checked = True
LV.ListItems(litm.Index).SubItems(3) = _
dct.Item(dct.Keys(i))
End If
Next litm
Next i

'Call GetSavedData
End Sub


"vqthomf" wrote:

The code for selecting the check box is
Private Sub LV_ItemCheck(ByVal Item As MSComctlLib.ListItem)
'

RcdNumber = Item.Index

Select Case Item.Checked
Case True
dct.Add LV.ListItems(RcdNumber), " "
Debug.Print "Added " & LV.ListItems(RcdNumber)
TextBox1.Text = ""
TextBox1.SetFocus
Case False
If dct.Exists(LV.ListItems(RcdNumber)) Then dct.Remove
(LV.ListItems(RcdNumber))
LV.ListItems(RcdNumber).SubItems(3) = ""
TextBox1.Text = ""
End Select

End Sub

This works as long as you are working on the listbox move away it wont
remove an item.

Private Sub cmdPrev_Click()
'
Dim itm, litm, strKey As String, i

If cmdNext.Enabled = False Then cmdNext.Enabled = True
MyNext = MyNext - 1
MyLabelNum = MyNext
MyLabelNum = LabelConfig(MyLabelNum)
If MyNext < 2 Then cmdPrev.Enabled = False
LV.ListItems.Clear
Call GetQuest

For i = 0 To dct.Count - 1
itm = dct.Keys(i)
For Each litm In LV.ListItems
If litm = itm Then
LV.ListItems(litm.Index).Checked = True
LV.ListItems(litm.Index).SubItems(3) =
dct.Item(dct.Keys(i))
End If
Next litm
Next i

'Call GetSavedData
End Sub
this will bring back everything including items that we thought had been
removed.

"Tom Ogilvy" wrote:

show the code that doesn't work.

--
Regards,
Tom Ogilvy


"vqthomf" wrote:

Hi we have a form with a next and prev buttons we are using the dictionary
object to hold the answers selected by the user, we use the check box
selection for each question selected if the check is true we add it to the
dictionary and if unticked we remove it from the dictionary then the use
would move to the next set of question that are loaded from a database. If
the use uses the prev button and the data is loaded from the database and the
check boxes are ticked from the dictionary, if the user unticks a check box
the code tries to remove this refference from then dictionary when we use the
exist it finds it but wont remove it? can any body explain reason for this.
TIA
Charles

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 104
Default Using the Dictionary object

our problem is that a key is found in the exist method of the dictionary but
wont remove it from the dictionary, if we stay working selecting and
unslecting the checkboxes everything works if we click the next button then
click the prev button the key is found but we get an error when the code
tries to remove the key?.
TIA
Charles

"Tom Ogilvy" wrote:

I get an error if I use the construct of

itm = dct.Keys(i)

So maybe you have an error handler clouding the issue.

I would use


Private Sub cmdPrev_Click()
'
Dim itm, litm, strKey As String, i, a

If cmdNext.Enabled = False Then cmdNext.Enabled = True
MyNext = MyNext - 1
MyLabelNum = MyNext
MyLabelNum = LabelConfig(MyLabelNum)
If MyNext < 2 Then cmdPrev.Enabled = False
LV.ListItems.Clear
Call GetQuest

a = dct.Keys
For i = 0 To dct.Count - 1
itm = a(i)
For Each litm In LV.ListItems
If litm = itm Then
LV.ListItems(litm.Index).Checked = True
LV.ListItems(litm.Index).SubItems(3) = _
dct.Item(dct.Keys(i))
End If
Next litm
Next i

'Call GetSavedData
End Sub


"vqthomf" wrote:

The code for selecting the check box is
Private Sub LV_ItemCheck(ByVal Item As MSComctlLib.ListItem)
'

RcdNumber = Item.Index

Select Case Item.Checked
Case True
dct.Add LV.ListItems(RcdNumber), " "
Debug.Print "Added " & LV.ListItems(RcdNumber)
TextBox1.Text = ""
TextBox1.SetFocus
Case False
If dct.Exists(LV.ListItems(RcdNumber)) Then dct.Remove
(LV.ListItems(RcdNumber))
LV.ListItems(RcdNumber).SubItems(3) = ""
TextBox1.Text = ""
End Select

End Sub

This works as long as you are working on the listbox move away it wont
remove an item.

Private Sub cmdPrev_Click()
'
Dim itm, litm, strKey As String, i

If cmdNext.Enabled = False Then cmdNext.Enabled = True
MyNext = MyNext - 1
MyLabelNum = MyNext
MyLabelNum = LabelConfig(MyLabelNum)
If MyNext < 2 Then cmdPrev.Enabled = False
LV.ListItems.Clear
Call GetQuest

For i = 0 To dct.Count - 1
itm = dct.Keys(i)
For Each litm In LV.ListItems
If litm = itm Then
LV.ListItems(litm.Index).Checked = True
LV.ListItems(litm.Index).SubItems(3) =
dct.Item(dct.Keys(i))
End If
Next litm
Next i

'Call GetSavedData
End Sub
this will bring back everything including items that we thought had been
removed.

"Tom Ogilvy" wrote:

show the code that doesn't work.

--
Regards,
Tom Ogilvy


"vqthomf" wrote:

Hi we have a form with a next and prev buttons we are using the dictionary
object to hold the answers selected by the user, we use the check box
selection for each question selected if the check is true we add it to the
dictionary and if unticked we remove it from the dictionary then the use
would move to the next set of question that are loaded from a database. If
the use uses the prev button and the data is loaded from the database and the
check boxes are ticked from the dictionary, if the user unticks a check box
the code tries to remove this refference from then dictionary when we use the
exist it finds it but wont remove it? can any body explain reason for this.
TIA
Charles



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default Using the Dictionary object

Hi. I can't tell, but is the Key you are adding a string, or some kind of
array?
I'm guessing from these two lines.

dct.Add LV.ListItems(RcdNumber), " "
'...
LV.ListItems(RcdNumber).SubItems(3) = ""

I would debug by making "LV.ListItems(RcdNumber)" a variable.

Private Sub LV_ItemCheck(ByVal Item As MSComctlLib.ListItem)
Dim Str As String

RcdNumber = Item.Index
Str = LV.ListItems(RcdNumber)

Select Case Item.Checked
Case True
dct.Add Str, Space(1)
Debug.Print "Added " & Str
TextBox1.Text = vbNullString
TextBox1.SetFocus
Case False
If dct.Exists(Str) Then dct.Remove (Str)
LV.ListItems(RcdNumber).SubItems(3) = vbNullString
TextBox1.Text = vbNullString
End Select

End Sub

--
Dana DeLouis
Windows XP & Office 2007


"vqthomf" wrote in message
...
The code for selecting the check box is
Private Sub LV_ItemCheck(ByVal Item As MSComctlLib.ListItem)
'

RcdNumber = Item.Index

Select Case Item.Checked
Case True
dct.Add LV.ListItems(RcdNumber), " "
Debug.Print "Added " & LV.ListItems(RcdNumber)
TextBox1.Text = ""
TextBox1.SetFocus
Case False
If dct.Exists(LV.ListItems(RcdNumber)) Then dct.Remove
(LV.ListItems(RcdNumber))
LV.ListItems(RcdNumber).SubItems(3) = ""
TextBox1.Text = ""
End Select

End Sub

This works as long as you are working on the listbox move away it wont
remove an item.

Private Sub cmdPrev_Click()
'
Dim itm, litm, strKey As String, i

If cmdNext.Enabled = False Then cmdNext.Enabled = True
MyNext = MyNext - 1
MyLabelNum = MyNext
MyLabelNum = LabelConfig(MyLabelNum)
If MyNext < 2 Then cmdPrev.Enabled = False
LV.ListItems.Clear
Call GetQuest

For i = 0 To dct.Count - 1
itm = dct.Keys(i)
For Each litm In LV.ListItems
If litm = itm Then
LV.ListItems(litm.Index).Checked = True
LV.ListItems(litm.Index).SubItems(3) =
dct.Item(dct.Keys(i))
End If
Next litm
Next i

'Call GetSavedData
End Sub
this will bring back everything including items that we thought had been
removed.

"Tom Ogilvy" wrote:

show the code that doesn't work.

--
Regards,
Tom Ogilvy


"vqthomf" wrote:

Hi we have a form with a next and prev buttons we are using the
dictionary
object to hold the answers selected by the user, we use the check box
selection for each question selected if the check is true we add it to
the
dictionary and if unticked we remove it from the dictionary then the
use
would move to the next set of question that are loaded from a database.
If
the use uses the prev button and the data is loaded from the database
and the
check boxes are ticked from the dictionary, if the user unticks a check
box
the code tries to remove this refference from then dictionary when we
use the
exist it finds it but wont remove it? can any body explain reason for
this.
TIA
Charles



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dictionary object: Error assigning user defined data type to item Paul Urbanus Excel Programming 2 December 1st 05 04:21 AM
HELP-Dictionary dfisch8 Excel Programming 3 August 22nd 05 08:27 PM
Dictionary Object in Windows XP Alan Beban[_2_] Excel Programming 5 March 13th 05 08:04 PM
dictionary Libby Excel Programming 0 November 15th 04 12:53 PM


All times are GMT +1. The time now is 08:26 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"