Results 1 to 14 of 14

Thread: iteration problem[resolved]

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    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.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. For i As Integer = 0 to 4
    2.     If Not check(i) Then
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: iteration problem

    ok, just missed that but after I fixed it I still get same errors???

  4. #4
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    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

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: iteration problem

    Im have:

    VB Code:
    1. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    2.        
    3.         For i = 0 To 4
    4.             If Not check(i) Then
    5.                 pic(i)a.Image = ImageList1.Images(2)
    6.             End If
    7.         Next
    8.     End Sub

    and still get same error?? How's that??

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    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

  7. #7
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  8. #8
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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:

    VB Code:
    1. Dim check(4) as boolean
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    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 ??

  10. #10
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: iteration problem

    I understand how you have been thinking but you simply cant do like that.
    VB Code:
    1. dim picBox(4) as PictureBox
    2. 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:
    1. picBox(0) = pic1a
    2. PicBox(1) = pic2a
    3. PicBox(2) = pic3a
    4. PicBox(3) = pic4a
    5. Picbox(4) = pic5a
    form load would be a good place to put it.
    Last edited by Atheist; Nov 17th, 2006 at 09:12 AM.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: iteration problem

    sorry if I sound stupid but this is giving me an error:

    VB Code:
    1. picBox(0) = pic1a
    2. PicBox(1) = pic2a
    3. PicBox(2) = pic3a
    4. PicBox(3) = pic4a
    5. Picbox(5) = pic5a

    do I have to do

    dim Picbox(0) as picturebox = pic1a.... ????

  12. #12
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    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:
    1. 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:
    1. PicBox(0) = pic1a
    2. PicBox(1) = pic2a
    3. etc...
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  13. #13
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: iteration problem

    no worries
    what does the error say?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  14. #14

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: iteration problem

    Many thanks found my mistake cos I had to change as well. Missed that. Many thanks Kimmy and Atheist.

    VB Code:
    1. For i = 0 To 4
    2.             If Not check(i) Then
    3.                 [COLOR=Green]Picbox[/COLOR](i).Image = ImageList1.Images(2)
    4.  
    5.             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
  •  



Click Here to Expand Forum to Full Width