help in visual basic..??

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • prkinlotpmpin
    New Member
    • Oct 2006
    • 6

    help in visual basic..??

    I am in a begginers Visual Basic class and have to find out how to navigate through records. In my program, I can navigate to the "next record" but I have no idea how to write the code to go to the "Previous Record." If anyone could help I would really appreciate it. Here's my code so far...

    'This form allows the user to view the data in the text file.

    Option Explicit
    Private intAccountInfor mation As Integer

    Private Sub cmdExit_click()
    Unload Me
    End Sub

    Private Sub cmdNext_click()
    Dim strRecord As String * 112
    Dim strName As String * 30
    Dim strAddress As String * 35
    Dim strCity As String * 25
    Dim strState As String * 2
    Dim strZip As String * 5
    Dim strAccount As String * 6
    Dim strBalance As String * 7
    Dim curBalance As Currency
    Get #intAccountInfo rmation, , strRecord
    If EOF(intAccountI nformation) Then
    MsgBox "There are no more records in the file."
    Else
    strName = Mid(strRecord, 1, 30)
    strAddress = Mid(strRecord, 31, 35)
    strCity = Mid(strRecord, 66, 25)
    strState = Mid(strRecord, 91, 2)
    strZip = Mid(strRecord, 93, 5)
    strAccount = Mid(strRecord, 97, 6)
    strBalance = Mid(strRecord, 105, 7)
    curBalance = CCur(strBalance ) / 100
    lblBalanceData. Caption = Format(curBalan ce, "$0.00")
    lblNameData.Cap tion = strName
    lblAddressData. Caption = strAddress
    lblCityData.Cap tion = strCity
    lblStateData.Ca ption = strState
    lblZipData.Capt ion = strZip
    lblAccountData. Caption = strAccount
    End If
    End Sub

    Private Sub cmdPrevious_Cli ck()

    End Sub

    Private Sub form_load()
    Dim strAccountInfor mation As String
    intAccountInfor mation = FreeFile
    strAccountInfor mation = App.Path & "\OutPutFile.tx t"
    Open strAccountInfor mation For Random Access Read As #intAccountInfo rmation Len = 112
    End Sub

    Private Sub form_unload(can cel As Integer)
    Close #intAccountInfo rmation
    End Sub
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    You could try something like...
    Code:
    Private Sub cmdPrevious_Click()
      Seek #intAccountInformation, Seek(#intAccountInformation)-112
      cmdNext_click
    End Sub

    Comment

    • prkinlotpmpin
      New Member
      • Oct 2006
      • 6

      #3
      Originally posted by Killer42
      You could try something like...
      Code:
      Private Sub cmdPrevious_Click()
        Seek #intAccountInformation, Seek(#intAccountInformation)-112
        cmdNext_click
      End Sub
      Thanks for trying to help, but that didn't work...

      Comment

      • willakawill
        Top Contributor
        • Oct 2006
        • 1646

        #4
        Originally posted by prkinlotpmpin
        Get #intAccountInfo rmation, , strRecord
        The space between the 2 commas is for the record number.
        Keep track of the records with a global long

        Dim lngCurrentRecor d As Long

        And call whichever record you wish.
        To move to the previous record:

        lngCurrentRecor d = lngCurrentRecor d -1

        Then

        Get #intAccountInfo rmation, lngCurrentRecor d, strRecord

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Originally posted by willakawill
          The space between the 2 commas is for the record number.
          Keep track of the records with a global long

          Dim lngCurrentRecor d As Long

          And call whichever record you wish.
          To move to the previous record:

          lngCurrentRecor d = lngCurrentRecor d -1

          Then

          Get #intAccountInfo rmation, lngCurrentRecor d, strRecord
          Oops!

          Good point. I was thinking "binary" rather than "random". My technique might work, if you use -1 rather than -112. Not that's it's necessarily a good way to do it, but it may work.

          Comment

          • prkinlotpmpin
            New Member
            • Oct 2006
            • 6

            #6
            No that wasn't succesful either... thanks for trying to help though. Is there anyone else what any suggestions..??

            Comment

            Working...