Results 1 to 6 of 6

Thread: write to txt file: subscript out of range

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2005
    Posts
    10

    Resolved write to txt file: subscript out of range

    hey all


    i got this problem:

    VB Code:
    1. Dim A As Integer
    2. Dim RijNamen(40) As String
    VB Code:
    1. A = 0
    2. Open File For Output As #1
    3.  For A = 1 to 80
    4.   Select Case A
    5.    Case Is < 30
    6.     Write #1, RijTijden(A)
    7.    Case Is > 30 And < 41
    8.     Write #1, RijHighScores(A - 30)
    9.    Case Is > 40
    10.     Write #1, RijNamen(A - 40)        '<--- here's the error
    11.  Next
    12. Close #1

    everything i put in the array RijNamen are dimmed as strings, but i guess the problem is there, i have no doubt where it could be
    Last edited by sheepke; Jun 20th, 2005 at 07:53 PM.

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: write to txt file: subscript out of range

    First of all you aren't handling when A is exactly 30 or exactly 40. Rewrite it this way

    VB Code:
    1. A = 0' not needed
    2. Open File For Output As #1
    3.  For A = 1 to 80
    4.   Select Case A
    5.    Case Is > 40 ' 41 to 80
    6.     Write #1, RijNamen(A - 40)
    7.    Case Is > 30 ' 31 to 40
    8.     Write #1, RijHighScores(A - 30)
    9.    Case Else ' 0 to 30
    10.     Write #1, RijTijden(A)
    11.  Next
    12. Close #1
    Put a breakpoint on the A = 1 to 80 line and step through the code and see what A is when it fails.

  3. #3
    Addicted Member
    Join Date
    May 2005
    Posts
    168

    Re: write to txt file: subscript out of range

    Hi,

    Martin is on the mark but this may help as well.

    VB Code:
    1. For A = 1 To 80
    2.         Select Case A
    3.             Case Is <= 30
    4.                 Write #1, RijTijden(A)
    5.             Case 31 To 40
    6.                 Write #1, RijHighScores(A - 30)
    7.             Case Is > 40
    8.                 Write #1, RijNamen(A - 40)
    9.             Case Else
    10.         End Select
    11. Next A

    Have a good one!
    BK

  4. #4

    Thread Starter
    New Member
    Join Date
    Jun 2005
    Posts
    10

    Re: write to txt file: subscript out of range

    i changed to much to know if it's good now
    but i have a new problem:
    if i have a variable like this: VarLine3 = "text"
    how can i get the " away?

  5. #5
    Fanatic Member vbasicgirl's Avatar
    Join Date
    Jan 2004
    Location
    Manchester, UK
    Posts
    1,016

    Re: write to txt file: subscript out of range

    use Print instead of Write.

    casey.

  6. #6

    Thread Starter
    New Member
    Join Date
    Jun 2005
    Posts
    10

    Re: write to txt file: subscript out of range

    Quote Originally Posted by vbasicgirl
    use Print instead of Write.

    casey.
    Great, thanks all.

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