Log in

View Full Version : VB. net Coding help



Piros
08-29-2008, 11:32 PM
Since this is an off-topic thread and there seems to be a good amount of programmers here I thought id ask for a bit of assistance. Im trying to code 3 check boxes so when they are checked they will add x amount to an additionalCharges variable and then show the addition in a label. Then if they are unchecked they will subtract the addition canceling it out.

I tried and if then else statement that looked like this

If me.xgolfcheckbox.checked then
additionalCharges = additionalCharges + 25
else additionalCharges = additionalCharges -25
End If

What am I doing wrong. Not really looking for the right coding just and idea to point me in the right direction.

-silencer-
08-30-2008, 12:13 AM
It's been awhile since I've worked with VB, but if you're trying to adjust the value like that immediately when a box is checked/unchecked, you need to call the checkbox's CheckChanged event:
(note, the syntax may be a little off.. it's been years since I've touched VB, so this is coming off the top of my head)


Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If (CheckBox1.Checked = True) Then
additionalCharges = additionalCharges + 25
Else
additionalCharges = additionalCharges - 25
End If
End Sub


Edit:
Generally I would have all the entry fields call an Update function that I write, then do all my work in the Update function to check all checkboxes/optionbuttons/values to calculate results. That way, you just have to call this Update function in the CheckChanged-type event for all objects that can be changed.