Dim curRecord Dim fileName Dim name Sub Main AddObject "PalmDB.Database", "PalmDB" fileName = currentpath & "\samples\keydbtest.pdb" name = "keydbtest.pdb" On Error Resume Next PalmDB.load fileName On Error Goto 0 PalmDB.Name = name PalmDB.Type = "data" PalmDB.Creator = "Kdbt" If PalmDB.Records.Count = 0 Then curRecord = -1 Else curRecord = 0 End If LoadRecord(curRecord) End Sub Sub LoadRecord(r) If r > -1 Then With PalmDb.Records(r) Dim s Dim offset offset = 0 s = .GetStringField() s = Left(s, Instr(s, chr(0)) - 1) Key.text = s offset = offset + Len(s) + 1 s = .GetStringField(offset) s = Left(s, Instr(s, chr(0)) - 1) Field1.text = s offset = offset + Len(s) + 1 s = .GetStringField(offset) s = Left(s, Instr(s, chr(0)) - 1) Field2.text = s End With Else Key.text = "" Field1.text = "" Field2.text = "" End If curRecord = r End Sub Function FindKey(key) Dim k Dim test FindKey = -1 If PalmDB.Records.Count > 0 Then For k = 0 to PalmDB.Records.Count - 1 test = PalmDB.Records(k).GetStringField(0) test = Left(test, Instr(test, chr(0)) - 1) If (test = key) Then FindKey = k Next End If End Function Sub Replace_Click If curRecord >= 0 Then WriteRecord(curRecord) End If End Sub Sub NewR_Click Dim where Dim s If FindKey(key.text) > -1 Then MsgBox "Key is already used" Else where = 0 ' Yes, this is a linear search, but you have a fast machine If PalmDb.Records.Count > 0 Then For where = 0 to PalmDb.Records.Count - 1 s = PalmDb.Records(where).GetStringField() s = Left(s, Instr(s, Chr(0)) - 1) If s > key.text Then Exit For End If Next End If PalmDb.Records.Add(where) WriteRecord(where) End If End Sub Sub WriteRecord(where) With PalmDb.Records(where) .Size = Len(key.text) + Len(field1.text) + Len(field2.text) + 3 .PutStringField key.text .PutStringField field1.text, Len(key.text) + 1 .PutStringField field2.text, Len(key.text) + Len(field1.text) + 2 End With SaveIt End Sub Sub SaveIt PalmDb.save fileName End Sub Sub NextR_Click If curRecord >= 0 Then If curRecord < PalmDB.Records.Count - 1 Then LoadRecord(curRecord + 1) End If End If End Sub Sub PrevR_Click If curRecord > 0 Then LoadRecord(curRecord - 1) End If End Sub Sub Find_Click Dim where where = FindKey(Key.text) If where >= 0 Then LoadRecord(where) Else MsgBox "The key was not found" End If End Sub