Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Dictionary object: Error assigning user defined data type to item | Excel Programming | |||
HELP-Dictionary | Excel Programming | |||
Dictionary Object in Windows XP | Excel Programming | |||
dictionary | Excel Programming |