Results 1 to 10 of 10

Thread: Runtime Error 9 in VB 6.0

  1. #1
    Join Date
    Mar 2009
    Posts
    56

    Runtime Error 9 in VB 6.0

    I have a slight problem with my program.

    I have this error with my code for a linear search. I am trying to get the file number from the text file it has been saved to and load the contents of the file into the textbox on another form, which loads up after the user has entered the filename they would like to see.

    The error is when it comes to the open previous button, I key in the filename, press enter and the Runtime Error 9; Subscript out of range error. I have the code below:

    Code:
    Private Sub ViewPrevious_Click()
    Dim Temp As String
    Dim i As Integer
    
    i = 1
    Found = False
    
    SavedUserChoices = InputBox$("Please enter the filename you would like to open", "Open Another Previous Configuration File")
    UserChoiceWindow.Show
    
    Open "N:\Computing\Advanced Higher Project\SavedConfigIndex.txt" For Input As #3
    Temp = Input(LOF(3), 3)
    Close #3
    
    
    ConfigSaveName() = Split(Temp, ",")
    
    Do While Found = False
        If SavedUserChoices = ConfigSaveName(i) Then
        Found = True
            Else
            i = i + 1
        End If
    Loop
    If Found = False Then
    SavedUserChoices = MsgBox("File not found!")
    Exit Sub
    ElseIf Found = True Then
        Open SavedUserChoices For Input As #1
        UserChoiceWindow.ChoicesChosen.Text = Input$(LOF(1), 1)
        Close #1
    End If
    End Sub
    CAN ANYONE HELP PLEASE.....!

  2. #2
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Runtime Error 9 in VB 6.0

    Try the following:-

    Code:
    Temp = Input(LOF(3), #3)

  3. #3
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Runtime Error 9 in VB 6.0

    Another line that could give you that error is this one

    Code:
    If SavedUserChoices = ConfigSaveName(i) Then

  4. #4
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Runtime Error 9 in VB 6.0

    OR do one thing try this it must work perfectly.........!

    Code:
    Private Sub ViewPrevious_Click()
    
    Dim Temp As String
    Dim i As Integer
    Dim Found As Boolean
    Dim SavedUserChoices As String
    Dim ConfigSaveName() As String
    i = 1
    Found = False
    
    SavedUserChoices = InputBox$("Please enter the filename you would like to open", "Open Another Previous Configuration File")
    UserChoiceWindow.Show
    
    Open "Open "N:\Computing\Advanced Higher Project\SavedConfigIndex.txt" For Input As #3" For Input As #3
    Temp = Input(LOF(3), #3)
    Text1.Text = Temp
    Close #3
    
    ConfigSaveName() = Split(Temp, ",")
    
    If UBound(ConfigSaveName) > 0 Then
        Do While Found = False
                If SavedUserChoices = ConfigSaveName(i) Then
                    Found = True
                Else
                    i = i + 1
                End If
        Loop
    End If
    If Found = False Then
        MsgBox("File not found!", vbOKOnly + vbInformation, "No Such File")
        Exit Sub
    Else
        Open SavedUserChoices For Input As #1
        UserChoiceWindow.ChoicesChosen.Text = Input$(LOF(1), 1)
        Close #1
    End If
    
    End Sub

  5. #5
    Join Date
    Mar 2009
    Posts
    56

    Re: Runtime Error 9 in VB 6.0

    I tried your code and it still seems to be stuck.

    When I click 'Debug', it points me towards this line:
    If SavedUserChoices = ConfigSaveName(i) Then

    Thanks for your help so far, look forward to it again...

  6. #6
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Runtime Error 9 in VB 6.0

    What do you mean by "stuck"?

    Give me an example of what is in ConfigSaveName.

  7. #7
    Join Date
    Mar 2009
    Posts
    56

    Re: Runtime Error 9 in VB 6.0

    The ConfigSaveName is the name of the array which holds the input the user has entered for the name of the file they would like to open.

  8. #8
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Runtime Error 9 in VB 6.0

    I need to know what is in the array. That is the example I'm after.

    I have no problems running the code I posted. If you are, then something else is wrong, and the only thing I can think of is what is actually in the array that I'm attempting to compare to what is in SavedUserChoices.

    BTW: You didn't say what you mean by "stuck"?

  9. #9
    Join Date
    Mar 2009
    Posts
    56

    Re: Runtime Error 9 in VB 6.0

    Sorry Hack.

    What I meant by stuck is that the same runtime error message appeared again.

    I'll explain the SavedUserChoices.

    This is used in the Save button subroutine that I also have which stores the captions of what the users have chosen, where the user is prompted with an InputBox to input a name for there choices. The SavedUserChoices then stores the input and writes the captions to a file.

    On the ViewPrevious button subroutine, the ConfigSaveName is where it is searching the Temp to see if there is a file with that name in the text file where it is being stored.

    Hope this helps,

  10. #10
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Runtime Error 9 in VB 6.0

    That error will happen if ConfigSaveName doesn't have anything in it. Are you sure that file isn't empty when you try to do the compare?

Similar Threads

  1. Replies: 3
    Last Post: 22-04-2009, 11:02 PM
  2. Microsoft Visual C++ Runtime Library... Runtime Error
    By Joko in forum Software Development
    Replies: 2
    Last Post: 17-02-2009, 09:52 PM
  3. Microsoft Visual C++ Runtime Library Symantec Runtime error
    By Ranchero in forum Windows XP Support
    Replies: 8
    Last Post: 27-09-2008, 09:08 AM
  4. Microsoft Visual C++ Runtime Library - Runtime Error
    By Leythos in forum Windows XP Support
    Replies: 3
    Last Post: 01-10-2007, 11:45 PM
  5. Replies: 6
    Last Post: 14-11-2006, 03:37 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,700,241.41897 seconds with 16 queries