Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
<pre lang="vb"><pre lang="vb">Dim ans As Double 
For z As Integer = 0 To ListBox1.Items.Count
            ans = Math.Sqrt((ListBox1.Items(z) - ListBox3.Items(z)) ^ 2 + Convert.ToInt32(ListBox2.Items(z) - ListBox4.Items(z)) ^ 2)

            ListBox5.Items.Add(ans)&lt;/pre&gt;</pre>



i try it, but error like this.
InvalidArgument=Value of '1' is not valid for 'index'.
anyone could help me?
Posted
Comments
Sergey Alexandrovich Kryukov 13-Nov-13 2:15am    
Where?
—SA
Thava Rajan 13-Nov-13 2:41am    
Where is error raise? are you sure the error is raise in one of the line you given

1 solution

use This ;)
VB
For z As Integer = 0 To ListBox1.Items.Count -1


Items is zero based ..

count returns 1 .. means there is only the item index 0
but you loop again through it with index 1 ..this is where you get your error
because there is no item(1)!

greets
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900