Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

New bie question

4 views
Skip to first unread message

ehab_a...@yahoo.com

unread,
Mar 27, 2005, 5:14:58 AM3/27/05
to
Executing of that code does nor write any data to phone.dat file becuase.....?


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

unread,
Mar 28, 2005, 2:08:32 AM3/28/05
to

What was the error you got?

Madhivanan

Wodka40°

unread,
Mar 28, 2005, 4:18:40 AM3/28/05
to
hpy_...@yahoo.com wrote:
> Executing of that code does nor write any data to phone.dat file


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


happy

unread,
Mar 28, 2005, 11:40:51 AM3/28/05
to
I do not have any errors just empty data are written to phone.dat . I
can see increasing of file size without any visible data!!

Wodka40°

unread,
Mar 29, 2005, 1:59:43 AM3/29/05
to
happy wrote:
> I do not have any errors just empty data are written to phone.dat . I
> can see increasing of file size without any visible data!!


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!

0 new messages