how to fix run time error 9 subscript out of range ?

You can talk about VB programming here

how to fix run time error 9 subscript out of range ?

Postby method » Mon Apr 06, 2009 5:40 pm


Hi all . I try to use the following code to load playlist text file into listboxes . The code is from locohacker musicbot(Music Bot Pal 8 or 9) .But unfortuenlty i get this error (but the listboxes get loaded with mp3 path and title)

Run-time error 9

subscript out of range


pointing at the following line:

'Check for unwanted vbCrLf (which would yeild a "")
If Len(strArr(intLB)) <> 0 Then

However, I get the above error if i only use the above code in my project but if i run loco full project i don't get that error!!could you guys help me fix this error so i be able to load playlist data in to listboxes without any error? Looking forward for replies.Thanks


Code: Select all
Private Sub Command1_Click()
'If Label1.Caption = "Not Connected" Then
'MsgBox "You must Connect to Room", vbCritical, "Not Connected"
'Else
Dim i As Long
Dim intLB As Long   'Is an index counter
Dim lngCtr As Long  'Represents the count of individual lines of data
Dim strOpenPathFile As String, strArr() As String, strBuffArr() As String
       
    With CommonDialog1
        .CancelError = True
        On Error GoTo CommDiaCancelled
        .Filter = "Text Files (*.txt)|*.txt|Word Doc (*.doc)|*.doc"
        .ShowOpen
    End With
   
    strOpenPathFile = CommonDialog1.FileName

    Open strOpenPathFile For Input As #1
        strArr = Split(Input(LOF(1), 1), vbCrLf)
    Close #1

    'Clear all the ListBoxs
    List1.Clear
    List2.Clear
     lngCtr = UBound(strArr)

    For intLB = 0 To lngCtr
   
CommDiaCancelled:
    If Err.Number = 32755 Then
        MsgBox "Cancel selected !"
        Exit Sub
    End If
        'Check for unwanted vbCrLf (which would yeild a "")
        If Len(strArr(intLB)) <> 0 Then

            'Split the Line of data
            strBuffArr = Split(strArr(intLB), vbTab)

            'Load the data into the ListBoxs

            List1.AddItem strBuffArr(0)
            List2.AddItem strBuffArr(1)
           
        End If
    Next
    Call Number(List1, " - ")
List1.Selected(0) = True
For i = List1.ListCount - 1 To 0 Step -1 ' counts list entries
    If List1.Selected(i) = True Then ' if selected then
        Text1.Text = List1.List(i) ' add to other list
        Text2.Text = List2.List(i)
        Text3.Text = List1.List(i)
        Text3.Text = Replace(Text3.Text, ".mp3", "")
        Text3.Text = Replace(Text3.Text, ".avi", "")
        Text3.Text = Replace(Text3.Text, ".asf", "")
        Text3.Text = Replace(Text3.Text, ".mpeg", "")
        Text3.Text = Replace(Text3.Text, ".mpg", "")
        Text3.Text = Replace(Text3.Text, ".wav", "")
        Text3.Text = Replace(Text3.Text, ".wmv", "")
        Text3.Text = Replace(Text3.Text, ".wma", "")
        Text3.Text = Replace(Text3.Text, ".cda", "")
        Text3.Text = Replace(Text3.Text, ".mid", "")
        Text3.Text = Replace(Text3.Text, ".midi", "")
        Text3.Text = Replace(Text3.Text, ".rm", "")
        RichTextBox3.TextRTF = Replace(RichTextBox1.TextRTF, "%song", Text3)
        If Option2.Value = True Then
        Else
        'Call RoomSend(RichTextBox3.TextRTF)
        End If
    End If
Next
'If Option1.Value = True Then
'wmp.URL = Text2.Text
'Timer1.Enabled = True
'Else
'MsgBox "You must press play then click on start buttom for the program to start", vbInformation, "Autoplay Off"
'End If
'End If
'Text10.Text = List1.ListCount
End Sub
method
imFiles Master
imFiles Master
 
Posts: 686
Joined: Tue Oct 18, 2005 11:12 am

Re: how to fix run time error 9 subscript out of range ?

Postby String » Tue Apr 07, 2009 1:52 am

Off hand, I'd say that your strArr is empty. Test to see is your array is populated.
-= Please ask your questions in the forum, not in pm.
String
imFiles Senior
imFiles Senior
 
Posts: 313
Joined: Mon Mar 10, 2008 7:06 am
Location: IDE


Return to Visual Basic Programming

 


  • Related topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 0 guests