[Problem]System.IndexOutOfRangeException

04/30/2015 14:04 Mr - Devil#1
Hey there,
I don't know what is wrong in Code .. :confused:
Please anyone tell me the right code for this project (New Media Player)
Code:
Public Class Form2
    ' Load Items in PlayList '
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ofd As New OpenFileDialog
        ofd.InitialDirectory = "C:\Users\Adminastrator\Desktop"
        ofd.Multiselect = True
        ofd.ShowDialog()
        For I As Integer = 0 To ofd.FileName.Count - 1
            ListBox1.Items.Add(ofd.FileNames(I))
            ListBox2.Items.Add(ofd.SafeFileNames(I))
        Next
        If ListBox1.Items.Count = 0 = True Then
            MsgBox("Please Load Items", MsgBoxStyle.Critical, "File Error !")
        Else
            ListBox1.SelectedIndex = 0
            ListBox2.SelectedIndex = 0
        End If
    End Sub
    'If Playlist2 Selected Index Changes, Playlist1 Selected Index changes'
    Private Sub ListBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox2.SelectedIndexChanged
        ListBox1.SelectedIndex = ListBox2.SelectedIndex
    End Sub
End Class
It's the code to playlist of my project
04/30/2015 18:02 Darkangel44#2
Hey,

on the first look, I can't spot any mistakes. If you use Visual Studio, you can tell us where the error occurs - that would be very helpful to spot the reason of your problem.


Regards,
DarkAngel44
04/30/2015 22:44 Mostey#3
OpenFileDialog.FileName is a string containing all file names that were selected in the dialog. The length of that string is not what you want for iterating through each individual file name.
04/30/2015 22:55 Mr - Devil#4
Quote:
Originally Posted by Mostey View Post
OpenFileDialog.FileName is a string containing all file names that were selected in the dialog. The length of that string is not what you want for iterating through each individual file name.
I don't understand you sorry ...
The wrong in
ListBox1.Items.Add(ofd.FileNames(I))
05/01/2015 17:45 const*#5
Quote:
Originally Posted by Mr - Devil View Post
I don't understand you sorry ...
The wrong in
ListBox1.Items.Add(ofd.FileNames(I))
Of course it is, you try to add an array where you should add a single variable.
05/01/2015 17:57 tolio#6
Use the correct property in your for loop.

[Only registered and activated users can see links. Click Here To Register...]
Quote:
Gets or sets a string containing the file name selected in the file dialog box.
vs.

[Only registered and activated users can see links. Click Here To Register...]
Quote:
Gets the file names of all selected files in the dialog box.
05/01/2015 18:17 Mr - Devil#7
Quote:
Originally Posted by *static_cast View Post
Of course it is, you try to add an array where you should add a single variable.
Look,should I replace Integer with Single or ?

Quote:
Originally Posted by tolio View Post
Use the correct property in your for loop.

[Only registered and activated users can see links. Click Here To Register...]


vs.

[Only registered and activated users can see links. Click Here To Register...]
I'll test
[Edit] I don't understand anything :( ,I'm beginner.
05/01/2015 18:41 Mostey#8
Quote:
Originally Posted by Mr - Devil View Post
[Edit] I don't understand anything :( ,I'm beginner.
Then you shouldn't just copy and paste code you do not understand. If you can't fix such trivial problems by yourself (even if we tell you what the problem is and how you can fix it), you should rather learn the basics than asking for complete code.
05/01/2015 19:13 Mr - Devil#9
Quote:
Originally Posted by Mostey View Post
Then you shouldn't just copy and paste code you do not understand. If you can't fix such trivial problems by yourself (even if we tell you what the problem is and how you can fix it), you should rather learn the basics than asking for complete code.
Listen , I'd learnt Vb coding from 2 years ... but now I forgot every thing about it ..
and the code not copy and paste :mofo: I created it.
Man I tested the program when I published it and it's working ..
but when I done load the files .. it gives me a warning msgbox then I press continue than it's working ..
so I want to remove this msgbox only
05/02/2015 01:17 Shawak#10
ofd.FileName.Count - 1 => ofd.FileNames.Count - 1
05/02/2015 01:51 Mr - Devil#11
Quote:
Originally Posted by Shawak View Post
ofd.FileName.Count - 1 => ofd.FileNames.Count - 1
Problem Solved ... :D:D:D
big thanks to you Shawak