Option Explicit
Dim gperson As PersonInfo
Dim gFilenum As Integer
Dim gRecordLen As Long
Dim gCurrentRecord As Long
Dim gLastRecord As Long
Private Sub Form_Load()
gRecordLen = Len(gperson)
gFilenum = FreeFile
Open "e:\programs\vb\eab\phone.dat" For Random As gFilenum Len = gRecordLen
gCurrentRecord = 1
gLastRecord = FileLen("e:\programs\vb\eab\phone.dat") / gRecordLen
If gLastRecord = 0 Then
gLastRecord = 1
End If
showcurrentrecord
End Sub
Public Sub showcurrentrecord()
Get #gFilenum, gCurrentRecord, gperson
txtname.Text = Trim(gperson.Name)
txtphone.Text = Trim(gperson.Phone)
txtcomments.Text = Trim(gperson.Comments)
frmmyphone.Caption = "السجل" + _
Str(gCurrentRecord) + " / " + Str(gLastRecord)
End Sub
Public Sub savecurrentrecord()
Get #gFilenum, gCurrentRecord, gperson
gperson.Name = txtname.Text
gperson.Phone = txtphone.Text
gperson.Comments = txtcomments.Text
Put #gFilenum, gCurrentRecord, gperson
End Sub
Private Sub imgnew_Click()
savecurrentrecord
gLastRecord = gLastRecord + 1
gperson.Name = ""
gperson.Phone = ""
gperson.Comments = ""
Put #gFilenum, gCurrentRecord, gperson
gCurrentRecord = gLastRecord
showcurrentrecord
txtname.SetFocus
End Sub
Madhivanan
he he he!
try this
Private Sub imgnew_Click()
gLastRecord = gLastRecord + 1
gCurrentRecord = gLastRecord
savecurrentrecord
'gperson.Name = ""
'gperson.Phone = ""
'gperson.Comments = ""
'Put #gFilenum, gCurrentRecord, gperson
'gCurrentRecord = gLastRecord
'showcurrentrecord
'txtName.SetFocus
End Sub
with an editor you see that now add record!
Remenber that at end "Close #gFilenum"f
By man!
;-)
--
Il Wodkino Nazionale è a : www.martek.it
Pagina Vb/Bestiario/Lamer Experience :
http://www.martek.it/go.asp?portamia=2 Quotefix e altro:
http://www.martek.it/go.asp?portamia=4
Usr: ICLVB Pw: amici
I repeat
Its a logical bug!
YOUR LOGICAL BUG!
....you reset the Usertype...
HERE
Private Sub imgnew_Click()
savecurrentrecord
gLastRecord = gLastRecord + 1
LOOK HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
gperson.Name = ""
gperson.Phone = ""
gperson.Comments = ""
Put #gFilenum, gCurrentRecord, gperson
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
YOU SEE???
You reset the type and THEN save on file A BLANK record!!!!
gCurrentRecord = gLastRecord
showcurrentrecord
txtname.SetFocus
End Sub
a possible solution (1 of many):
......
Private Sub imgnew_Click()
gLastRecord = gLastRecord + 1
gCurrentRecord = gLastRecord
savecurrentrecord
'gperson.Name = ""
'gperson.Phone = ""
'gperson.Comments = ""
'Put #gFilenum, gCurrentRecord, gperson
'gCurrentRecord = gLastRecord
'showcurrentrecord
'txtName.SetFocus
End Sub
.........
Bye man!