469,081 Members | 1,834 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,081 developers. It's quick & easy.

New bie question

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
Jul 17 '05 #1
4 2594

What was the error you got?

Madhivanan

Jul 17 '05 #2
hp******@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
Jul 17 '05 #3
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!!

Jul 17 '05 #4
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!
--
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
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Mohammed Mazid | last post: by
3 posts views Thread by Stevey | last post: by
10 posts views Thread by glenn | last post: by
53 posts views Thread by Jeff | last post: by
56 posts views Thread by spibou | last post: by
2 posts views Thread by Allan Ebdrup | last post: by
3 posts views Thread by Zhang Weiwu | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.