Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > .NET Languages
You last visited: Today at 21:22

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[Problem]System.IndexOutOfRangeException

Discussion on [Problem]System.IndexOutOfRangeException within the .NET Languages forum part of the Coders Den category.

Reply
 
Old   #1
 
Mr - Devil's Avatar
 
elite*gold: 0
Join Date: Apr 2015
Posts: 16
Received Thanks: 2
[Problem]System.IndexOutOfRangeException

Hey there,
I don't know what is wrong in Code ..
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
Mr - Devil is offline  
Old 04/30/2015, 18:02   #2
 
Darkangel44's Avatar
 
elite*gold: 15
Join Date: Oct 2010
Posts: 182
Received Thanks: 38
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
Darkangel44 is offline  
Old 04/30/2015, 22:44   #3


 
elite*gold: 1091
Join Date: Jun 2007
Posts: 19,836
Received Thanks: 7,180
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.
Mostey is offline  
Old 04/30/2015, 22:55   #4
 
Mr - Devil's Avatar
 
elite*gold: 0
Join Date: Apr 2015
Posts: 16
Received Thanks: 2
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))
Mr - Devil is offline  
Old 05/01/2015, 17:45   #5
 
const*'s Avatar
 
elite*gold: 0
Join Date: Mar 2015
Posts: 776
Received Thanks: 313
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.
const* is offline  
Old 05/01/2015, 17:57   #6
 
tolio's Avatar
 
elite*gold: 2932
The Black Market: 169/1/0
Join Date: Oct 2009
Posts: 6,966
Received Thanks: 1,097
Use the correct property in your for loop.


Quote:
Gets or sets a string containing the file name selected in the file dialog box.
vs.


Quote:
Gets the file names of all selected files in the dialog box.
tolio is offline  
Thanks
1 User
Old 05/01/2015, 18:17   #7
 
Mr - Devil's Avatar
 
elite*gold: 0
Join Date: Apr 2015
Posts: 16
Received Thanks: 2
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.




vs.

I'll test
[Edit] I don't understand anything ,I'm beginner.
Mr - Devil is offline  
Old 05/01/2015, 18:41   #8


 
elite*gold: 1091
Join Date: Jun 2007
Posts: 19,836
Received Thanks: 7,180
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.
Mostey is offline  
Old 05/01/2015, 19:13   #9
 
Mr - Devil's Avatar
 
elite*gold: 0
Join Date: Apr 2015
Posts: 16
Received Thanks: 2
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 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
Mr - Devil is offline  
Old 05/02/2015, 01:17   #10



 
Shawak's Avatar
 
elite*gold: 0
The Black Market: 259/0/0
Join Date: Apr 2010
Posts: 10,289
Received Thanks: 3,613
ofd.FileName.Count - 1 => ofd.FileNames.Count - 1
Shawak is offline  
Thanks
1 User
Old 05/02/2015, 01:51   #11
 
Mr - Devil's Avatar
 
elite*gold: 0
Join Date: Apr 2015
Posts: 16
Received Thanks: 2
Quote:
Originally Posted by Shawak View Post
ofd.FileName.Count - 1 => ofd.FileNames.Count - 1
Problem Solved ...
big thanks to you Shawak
Mr - Devil is offline  
Reply


Similar Threads Similar Threads
Flag-Sro l Cap110 l Coin System l Fight-Power System l New System l High Rate
07/06/2014 - SRO PServer Advertising - 1 Replies
http://i.epvpimg.com/Q62Bb.png if you Like Old School Join us Web Site Flag-Sro - Silkroad Online Private Server Download Flag-Sro - Silkroad Online Private Server Register Flag-Sro - Silkroad Online Private Server FacBook https://www.facebook.com/pages/Flag-Sro/423472161 101339



All times are GMT +1. The time now is 21:23.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.