Results 1 to 9 of 9

Thread: run-time error 59

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2001
    Location
    az
    Posts
    4

    run-time error 59

    I know this is gonna be something really stupid, but for some reason, I can't locate the problem.

    I keep getting an error 59 when trying to get this info from a file into an array. Here is the code:

    Open (App.Path & "\" & "RegSales.txt") For Random As #intFNum
    'im not sure what to put for len

    Do Until EOF(intFNum)
    Get #intFNum, intCounter, varLine
    strArray(intCounter) = varLine
    intCounter = intCounter + 1
    Loop


    Please help. This is a homework assignment, and I need to get it done tonight.

    Thanks in advance,

    Skyler

  2. #2
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    at what line does the error occur, and what is the error description?

    is app.path a local path or does the program reside on a server?
    -= a peet post =-

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2001
    Location
    az
    Posts
    4

    at the get statement

    the error occurs at the get statement line

    Get #intFNum, intCounter, varLine

  4. #4
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    I'll do some quoting

    MSDN

    Bad record length (Error 59)
    The length of a record variable for a Get or Put statement does not match the length specified in the corresponding Open statement. Because a two- byte descriptor is always added to a variable-length string Put to a random access file, the variable-length string must be at least two characters shorter than the record length specified in the Len clause of the Open statement.

    Variant data types also require a two-byte descriptor. Variants containing variable-length strings require a four-byte descriptor. Therefore, for variable-length strings in a Variant, the string must be at least 4 bytes shorter than the record length specified in the Len clause.
    does that help u in any way?
    -= a peet post =-

  5. #5
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    -= a peet post =-

  6. #6
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    Belgium/Antwerp
    Posts
    275
    I do not know if you want to use the get statement for a specific reason, but with this example you read the file line by line and stock it in a dynamic array.

    Remeber to always use the option explicit statement to avoid errors.

    VB Code
    Option Explicit

    Dim intFNum As Integer
    Dim intcounter As Integer
    Dim varline As String
    Dim strArray() As String
    Private Sub test()
    intFNum = FreeFile
    intcounter = 0
    Open ("C:" & "\" & "RegSales.txt") For Input As #intFNum
    'im not sure what to put for len

    Do Until EOF(intFNum)
    intcounter = intcounter + 1
    Input #intFNum, varline

    ReDim Preserve strArray(intcounter)

    strArray(intcounter) = varline

    Loop
    Close #intFNum

    End Sub

    Greetz, Luc

  7. #7

    Thread Starter
    New Member
    Join Date
    Sep 2001
    Location
    az
    Posts
    4

    solved it

    thanks a lot peet! i am no longer getting the error 59. now i am getting a error 9 (subscript out of range) on this line:

    strArray(intCounter) = varLine

    but hopefully, i will be able to figure it out.

    thanks again,

    skyler

  8. #8
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629


    intCounter prob. to big
    -= a peet post =-

  9. #9

    Thread Starter
    New Member
    Join Date
    Sep 2001
    Location
    az
    Posts
    4

    LucGuldentops, you are a life saver!!!

    thanks so much LucGuldentops...that is exactly what i was looking to do! you are my hero.

    thanks again you guys for taking the time to post and help out,

    skyler

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width