for each loop in a checkbox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have six checkboxes so I went to see it and os them are checked and if so
add 50 to the total
heres my code

Dim arrchecks(6) As CheckBox
arrchecks(0) = Me.chkChicken
arrchecks(1) = Me.chkMushrooms
arrchecks(2) = Me.chkPepperoni
arrchecks(3) = Me.chkECheese
arrchecks(4) = Me.chkHam
arrchecks(5) = Me.chkPeppers

For Each chk As CheckBox In arrchecks
chk.CheckState = CheckState.Checked
total = +50

Next chk
I know I am doing something wrong
Thanks
 
freddy said:
I have six checkboxes so I went to see it and os them
are checked and if so add 50 to the total
heres my code

Dim arrchecks(6) As CheckBox
arrchecks(0) = Me.chkChicken
arrchecks(1) = Me.chkMushrooms
arrchecks(2) = Me.chkPepperoni
arrchecks(3) = Me.chkECheese
arrchecks(4) = Me.chkHam
arrchecks(5) = Me.chkPeppers

For Each chk As CheckBox In arrchecks
chk.CheckState = CheckState.Checked
total = +50

Next chk

\\\
Private AllChecked As Boolean = True
For Each chk As CheckBox In ArrChecks
If Not chk.Checked Then
AllChecked = False
Exit For
End If
Next chk
If AllChecked THen
Total = Total + 50
End If
///
 
freddy said:
I have no if statement, but I do need one right?

Thats what you said, right here:

Since adding 50 is conditional, you need to use the conditional
commands. In this case that is going to be the If statement....

LFS
 
here it is:

Dim arrchecks(6) As CheckBox
arrchecks(0) = Me.chkChicken
arrchecks(1) = Me.chkMushrooms
arrchecks(2) = Me.chkPepperoni
arrchecks(3) = Me.chkECheese
arrchecks(4) = Me.chkHam
arrchecks(5) = Me.chkPeppers

For Each chk As CheckBox In arrchecks
If chk.CheckState.Checked Then
total = total + 50
End If

Next chk
 
no it does not work, I am still trying new code
Dim t = 50


Dim arrchecks(6) As CheckBox
arrchecks(0) = Me.chkChicken
arrchecks(1) = Me.chkMushrooms
arrchecks(2) = Me.chkPepperoni
arrchecks(3) = Me.chkECheese
arrchecks(4) = Me.chkHam
arrchecks(5) = Me.chkPeppers

For Each chk As CheckBox In arrchecks
If chk.CheckState.Checked Then
End If
t = t + 50
Next chk
 
freddy said:
no it does not work, I am still trying new code

Keep trying, nothing cements the learning process faster
than finding the answer yourself.
For Each chk As CheckBox In arrchecks
If chk.CheckState.Checked Then
End If
t = t + 50
Next chk

How did the + 50 get outside of the conditional block?
And, what prompted you to use CheckState? Don't be
afraid to open up Help and read about the checkbox and
its properties....

LFS
 
There's also something wrong witth your array declaration and you should dim
your t as something

greetz Peter
 
I see it , but how can I learn if someone tell me here copy my code it works
- I want to learn. If you can not tell me whats wrong with my array that's
ok, but don't give me the run around
Thanks
 
I went to see if any of them are checked andir so add 50. So if three are
ckecked add 50 three times
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top