View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Dana DeLouis Dana DeLouis is offline
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