New bie question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • hpy_awad@yahoo.com

    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:\pro grams\vb\eab\ph one.dat") / gRecordLen
    If gLastRecord = 0 Then
    gLastRecord = 1
    End If
    showcurrentreco rd
    End Sub

    Public Sub showcurrentreco rd()
    Get #gFilenum, gCurrentRecord, gperson
    txtname.Text = Trim(gperson.Na me)
    txtphone.Text = Trim(gperson.Ph one)
    txtcomments.Tex t = Trim(gperson.Co mments)
    frmmyphone.Capt ion = "السجل" + _
    Str(gCurrentRec ord) + " / " + Str(gLastRecord )
    End Sub

    Public Sub savecurrentreco rd()
    Get #gFilenum, gCurrentRecord, gperson
    gperson.Name = txtname.Text
    gperson.Phone = txtphone.Text
    gperson.Comment s = txtcomments.Tex t
    Put #gFilenum, gCurrentRecord, gperson
    End Sub

    Private Sub imgnew_Click()
    savecurrentreco rd
    gLastRecord = gLastRecord + 1
    gperson.Name = ""
    gperson.Phone = ""
    gperson.Comment s = ""
    Put #gFilenum, gCurrentRecord, gperson
    gCurrentRecord = gLastRecord
    showcurrentreco rd
    txtname.SetFocu s
    End Sub
  • Madhivanan

    #2
    Re: New bie question


    What was the error you got?

    Madhivanan

    Comment

    • Wodka40°

      #3
      Re: New bie question

      hpy_awad@yahoo. com wrote:[color=blue]
      > Executing of that code does nor write any data to phone.dat file[/color]


      he he he!

      try this

      Private Sub imgnew_Click()

      gLastRecord = gLastRecord + 1
      gCurrentRecord = gLastRecord
      savecurrentreco rd
      'gperson.Name = ""
      'gperson.Phone = ""
      'gperson.Commen ts = ""
      'Put #gFilenum, gCurrentRecord, gperson
      'gCurrentRecord = gLastRecord
      'showcurrentrec ord
      'txtName.SetFoc us
      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:

      Usr: ICLVB Pw: amici


      Comment

      • happy

        #4
        Re: New bie question

        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!!

        Comment

        • Wodka40°

          #5
          Re: New bie question

          happy wrote:[color=blue]
          > 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!![/color]


          I repeat
          Its a logical bug!
          YOUR LOGICAL BUG!

          .....you reset the Usertype...

          HERE
          Private Sub imgnew_Click()
          savecurrentreco rd
          gLastRecord = gLastRecord + 1



          LOOK HERE!!!!!!!!!!! !!!!!!!!!!!!!!! !!!!!!!!!!!
          gperson.Name = ""
          gperson.Phone = ""
          gperson.Comment s = ""
          Put #gFilenum, gCurrentRecord, gperson

          !!!!!!!!!!!!!!! !!!!!!!!!!!!!!! !!!!!!!!!!!!!!! !!!!!!!!!!!!!!
          YOU SEE???
          You reset the type and THEN save on file A BLANK record!!!!


          gCurrentRecord = gLastRecord
          showcurrentreco rd
          txtname.SetFocu s
          End Sub


          a possible solution (1 of many):
          .......
          Private Sub imgnew_Click()

          gLastRecord = gLastRecord + 1
          gCurrentRecord = gLastRecord
          savecurrentreco rd
          'gperson.Name = ""
          'gperson.Phone = ""
          'gperson.Commen ts = ""
          'Put #gFilenum, gCurrentRecord, gperson
          'gCurrentRecord = gLastRecord
          'showcurrentrec ord
          'txtName.SetFoc us
          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:

          Usr: ICLVB Pw: amici


          Comment

          Working...