Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with combobox logic

Status
Not open for further replies.

montejr

Programmer
May 24, 2001
42
0
0
US
All,
Let me first say that I don't consider myself to be a VB programmer/scripter. I'm playing around with a small demo for a presentation.

I have a combo box with no and yes values. If no is selected, no points are added to a label showing a total. If I select yes, 5 points are added and the label changes to 5. If I go back to no, it does not revert to 0. Can someone help me out with my logic?

Thanks,
Monte

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.SelectedIndex = 0 Then
total = total + 0
ElseIf ComboBox1.SelectedIndex = 1 Then
total = total + 5
End If

Label104.Text = total
Label16.Text = total
Label14.Text = total
End Sub
 
This looks like .Net

Are you keeping a running total or just toggling back between 0 and 5?
Code:
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
 If ComboBox1.SelectedIndex = 0 Then
            total =  0
        ElseIf ComboBox1.SelectedIndex = 1 Then
            total =  5
        End If
  Label104.Text = total
        Label16.Text = total
        Label14.Text = total
    End Sub

if you want a running total then something like this may work.

Code:
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Static Total as Integer = 0
 If ComboBox1.SelectedIndex = 0 Then
            total +=  0
        ElseIf ComboBox1.SelectedIndex = 1 Then
            total +=  5
        End If
  Label104.Text = total
        Label16.Text = total
        Label14.Text = total
    End Sub
I didn't test this but hopefully it will help.
 
Thanks jadams0173. This is getting me on my way. One thing I forgot to mention is that there are radiobuttons on the form as well. If they are selected, a point gets added to the total. So with this code, going back to 0 sets the whole total back to 0 instead of subtracting 5. So if I have a radio button selected and yes in the combo box the total is 6. If I select no, the total should go back to 1 instead of 0.

Thanks for your help - I really appreciate it.
 
Hey montejr,

I really don't understand how the radio buttons play into the equation. You should have at least 2 radio buttons which could give you about 6 possible combinations between the combo box (Yes and No) and the radio buttons. If you have yes in the cbo box and select radio button 1 what happens? What happens if you have yes in the cbo box and select radio button 2? Same questions with no.

Can you post all the code you have to this point?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top