I found the problem. It turns out that a key of 1 (integer) is not the same as a key of 1 (double). When the dictionary entry is made, the an integer (Vnum) is used, when I tried to read the key, I used CDbl(Vehiclepop.Text), which is obviously a double, to try to get the record. All I had to do to make it work was change the second routine to
Dim V As Vehicle Dim Key As Integer Key = CDbl(VehiclePop.Text) V = VehicleDict.Value(Key) Paul Dobbs Software Engineer, Staff Lockheed Martin Missiles and Fire Control Phone (972) 603-1244 Fax (972) 603-2017 > _____________________________________________ > From: Dobbs, Paul > Sent: Thursday, June 22, 2006 12:42 PM > To: '[email protected]' > Subject: Dictionary Key Not Found -- but it's there! > > I'm getting a key not found error which I can't understand, since the > key appears to be in the dictionary. > > The dictionary is populated by the following routine: > > Dim F As FolderItem > Dim S As TextInputStream > Dim VNum As Integer > Dim V As Vehicle > > VehicleDict = New Dictionary > VehiclePop.DeleteAllRows > > F = PreferencesFolder.Child("JAUSPrefs.txt") > If F <> Nil Then > S = F.OpenAsTextFile > If S <> Nil Then > IPEdt.Text = S.ReadLine > PortEdt.Text = S.ReadLine > While Not S.EOF > VNum = Cdbl(S.ReadLine) //<-----here > to > VehiclePop.AddRow Cstr(VNum) > V = New Vehicle > V.ID = VNum > VehicleDict.Value(VNum) = V //<--- here > Wend > S.Close > //<---- breakpoint here > Else > Dim M As New MessageDialog > > M.Icon = MessageDialog.GraphicCaution > M.Title = "Data Read Failure" > M.Message = "Unable to read data" > M.Explanation = "The IP address, port and vehicle list were not > read." > Call M.ShowModal > End If > End If > > In the lines marked "here to here," this routine reads a file and > creates a member of the vehicle class for each vehicle number in the > file. If I put a breakpoint at the S.Close statement, I can look at > the dictionary and see that it has 5 entries with keys of 1, 38, 49, > 54 and 67, which is exactly what I would expect, knowing that those > vehicle numbers are in the file. > > Shortly after that, I run another routine that wants to make an > addition to the dictionary entry for one of the vehicles. The first > lines of that routine are: > > Dim V As Vehicle > > V = VehicleDict.Value(CDbl(VehiclePop.Text)) //<---------- key not > found > > I am getting a Key Not Found error at the second statement. In the > debugger, the value of VehiclePop.Text is "1" and the dictionary still > has be 5 entries (keys of 1, 38, 49, 54 and 67), so it appears that > the key really is there. > > I am running RB2006r2 on Win XP Pro. Any ideas? > Paul Dobbs > Software Engineer, Staff > Lockheed Martin Missiles and Fire Control > Phone (972) 603-1244 > Fax (972) 603-2017 > _______________________________________________ Unsubscribe or switch delivery mode: <http://www.realsoftware.com/support/listmanager/> Search the archives of this list here: <http://support.realsoftware.com/listarchives/lists.html>
