Link to home
Start Free TrialLog in
Avatar of guyanese_princess02
guyanese_princess02

asked on

Runtime error: '59' Bad Record Length

I am writing a program to read information from a file and output it to another file. But, when i run the program i get a runtime error 59. heres my code...
the stateInfo is defined in a module

    Dim Current As stateInfo
    Open "States.dat" For Random As #1 Len = Len(Current)
    count = 0
   
    Open "States.txt" For Input As #2
    Do While Not EOF(1)
        Input #2, tName, tAbbrev, tYear, tArea, tPop
        'write to file
        Current.sName = tName
        Current.sAbbrev = tAbbrev
        Current.sYear = tYear
        Current.sArea = tArea
        Current.sPop = tPop
        count = count + 1
        Put #1, count, Current
    Loop
ASKER CERTIFIED SOLUTION
Avatar of aelatik
aelatik
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of anv
anv

hi guyanese_princess02

Use the get method for reading the data from "states.dat" file...

anv
Avatar of guyanese_princess02

ASKER

thank u: aelatik, anv.... i no longer get any errors. But when i run the program, the file is created but nuthing is written inside.. what am i doing wrong? heres my code...

Option Explicit
    Dim recordNum As Integer     '---counts number of entries in file
    Dim Current(50) As stateInfo

Private Sub cmdBegin_Click()
    Dim tName As String
    Dim tAbbrev As String
    Dim tYear As Single
    Dim tArea As Double
    Dim tPop As Double

    recordNum = 0
   
    Open "STATES.txt" For Input As #2
    Do While Not EOF(2)
        Input #2, tName, tAbbrev, tYear, tArea, tPop
        'write to file
        Current(recordNum).sName = tName
        Current(recordNum).sAbbrev = tAbbrev
        Current(recordNum).sYear = tYear
        Current(recordNum).sArea = tArea
        Current(recordNum).sPop = tPop
       
        recordNum = recordNum + 1
        Put #1, recordNum, Current(recordNum)
    Loop
   
    Close #2
       
End Sub

Private Sub Form_Load()
    Dim state As stateInfo
    Open "State.dat" For Random As #1 Len = Len(state)
 
End Sub