|
-
Nov 17th, 2006, 08:27 AM
#1
Thread Starter
Frenzied Member
iteration problem[resolved]
hey why cant I loop through ?? How can I correct it?? I get these 3 errors
End of statement expected.
Name 'check' is not declared.
Name 'pic' is not declared.
check1 ....5 are declared as booean
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim i As Integer
For i = 1 To 5
If check(i) = False Then
pic(i)a.Image = ImageList1.Images(2)
End If
Next
End Sub
Last edited by angelica; Nov 17th, 2006 at 09:15 AM.
-
Nov 17th, 2006, 08:31 AM
#2
Re: iteration problem
All .NET arrays and collections are zero based, so if check is an array with 5 elements or a collection with 5 items then they are at indexes zero to 4, not 1 to 5.
Also, many people seem to want to do that but if your object is already a boolean then why compare it to a second boolean to get a third boolean? Just use the first boolean to begin with:
VB Code:
For i As Integer = 0 to 4
If Not check(i) Then
-
Nov 17th, 2006, 08:34 AM
#3
Thread Starter
Frenzied Member
Re: iteration problem
ok, just missed that but after I fixed it I still get same errors???
-
Nov 17th, 2006, 08:40 AM
#4
Fanatic Member
Re: iteration problem
Where have you declared the arrays check() and pic()?
If your problem has been solved then please mark the thread [RESOLVED].
If i have helped then please Rate my post 
-
Nov 17th, 2006, 08:41 AM
#5
Thread Starter
Frenzied Member
Re: iteration problem
Im have:
VB Code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
For i = 0 To 4
If Not check(i) Then
pic(i)a.Image = ImageList1.Images(2)
End If
Next
End Sub
and still get same error?? How's that??
-
Nov 17th, 2006, 08:43 AM
#6
Thread Starter
Frenzied Member
Re: iteration problem
I declared them in Form scope and the picture boxes are named at design..
Dim check1, check2, check3, check4, check0 As Boolean
-
Nov 17th, 2006, 08:44 AM
#7
Re: iteration problem
-on what lines do you get the errors?
-where have you declared the arrays?
-why do you have an 'a' the (i) in pic(i)a.image?
Edit: oh oops ignore question 2
-
Nov 17th, 2006, 08:46 AM
#8
Re: iteration problem
Pictureboxes are named at design time? You mean that the picturebox names are pic1a pic2a and so on? ..Well that certainly wont work, that is no way to create an array of pictureboxes.
And the same goes for your boolean variables. They are not an array. You should do:
-
Nov 17th, 2006, 08:47 AM
#9
Thread Starter
Frenzied Member
Re: iteration problem
Guess I have to declare an array somewhere cos I have done so for the check 0...5.
but for the pictureboxes named pic0a... pic4a I since they are named at design I dont know really how to solve that??
The errors are on check and pic saying Not declared?
Give my an example pls cos Im confused ??
-
Nov 17th, 2006, 08:51 AM
#10
Re: iteration problem
I understand how you have been thinking but you simply cant do like that.
VB Code:
dim picBox(4) as PictureBox
dim check(4) as Boolean
That is the proper way to do arrays.
You could create the pictureboxes by code, but since youve already added them in design time you could just assign them to their own place in the picBox array like this:
VB Code:
picBox(0) = pic1a
PicBox(1) = pic2a
PicBox(2) = pic3a
PicBox(3) = pic4a
Picbox(4) = pic5a
form load would be a good place to put it.
Last edited by Atheist; Nov 17th, 2006 at 09:12 AM.
-
Nov 17th, 2006, 09:01 AM
#11
Thread Starter
Frenzied Member
Re: iteration problem
sorry if I sound stupid but this is giving me an error:
VB Code:
picBox(0) = pic1a
PicBox(1) = pic2a
PicBox(2) = pic3a
PicBox(3) = pic4a
Picbox(5) = pic5a
do I have to do
dim Picbox(0) as picturebox = pic1a.... ????
-
Nov 17th, 2006, 09:08 AM
#12
Fanatic Member
Re: iteration problem
Not necessarily, you just need to declare the array as a picturebox, so before you assign values to the elements in the array make sure you have the line
VB Code:
Dim PicBox(5) as picturebox 'only put the 5 if you know exactly how many elements you are going to need in the array. Otherwise you will have to redimension the array.
and then you can go on to say
VB Code:
PicBox(0) = pic1a
PicBox(1) = pic2a
etc...
If your problem has been solved then please mark the thread [RESOLVED].
If i have helped then please Rate my post 
-
Nov 17th, 2006, 09:09 AM
#13
Re: iteration problem
no worries
what does the error say?
-
Nov 17th, 2006, 09:13 AM
#14
Thread Starter
Frenzied Member
Re: iteration problem
Many thanks found my mistake cos I had to change as well. Missed that. Many thanks Kimmy and Atheist.
VB Code:
For i = 0 To 4
If Not check(i) Then
[COLOR=Green]Picbox[/COLOR](i).Image = ImageList1.Images(2)
End If
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|