tags:

views:

43

answers:

1

Hi I have a numeric up down, and I want it to either add or minus one depending if the up or down arrow is pressed. I have the code below but it only works to minus one from the varible?

  Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
        If ComboBox1.SelectedIndex = 0 Then
            seatsA = seatsA - 1
            TextBox2.Text = seatsA
        ElseIf ComboBox1.SelectedIndex = 1 Then
            seatsB = seatsB - 1
            TextBox2.Text = seatsB
        ElseIf ComboBox1.SelectedIndex = 2 Then
            seatsC = seatsC - 1
            TextBox2.Text = seatsC
        End If
End Sub

Edit: If the numeric updown value is changed, the varible stores this change, each comboBox has its own varible as it needs to store the value for each. I.e if seatsA is 20, when the user goes back to selcted index one 20 is shown.

Seats start with a number...such as 75, when the numeric updown is increased, one is taken off the seats value for each seat (a,b,c)

Thanks

+1  A: 

Do you want TextBox2 to have the same value as NumericUpDown1? If it's the case, you can simply do this:

Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
        TextBox2.Text = NumericUpDown1.Value
End Sub

Edit:

From what I understand of your edit, what you want to do here is set the correct value to your NumericUpDown when the selected index changes. You can do something like this:

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        If ComboBox1.SelectedIndex = 0 Then
            NumericUpDown1.Value = seatsA
        ElseIf ComboBox1.SelectedIndex = 1 Then
            NumericUpDown1.Value = seatsB
        End If
End Sub

Then to save a value change, you could do something like:

Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
        If ComboBox1.SelectedIndex = 0 Then
            seatsA = NumericUpDown1.Value
        ElseIf ComboBox1.SelectedIndex = 1 Then
            seatsB = NumericUpDown1.Value
        End If
End Sub

Other edit:

OK... I understand what you're trying to do now...

I can think of two strategies:

  1. In your form, have a LastNumericUpDownValue member in which you keep the last value of the numericupdown. Then you compare the current value to the last value, and you'll know if the value has been incremented or decremented.

  2. Keep the original number of seats as a member of the form when you load the form. Then when the NumericUpDownValue1 changes you can calculate that seatA = originalNumberOfSeats - seatsRequired (the value of NumericUpDown1)

Meta-Knight
thanks but it needs to show a different value if the selected index on the ComboBox is changed, so if its index 1 then the numeric up down would show seatsB value.
Elliott
no need to do a `selectedindex` check. just `TextBox2.Text = NumericUpDown1.Value`
Jason
seatsA etc have a value to begin with so the minus or plus one needs to be taken off this. Sorry if I wasnt clear.
Elliott
@Elliot: That's why when the selected index changes I set the value corresponding to seatA or seatB or whatever ;-) You should also set the correct value to the NumericUpDown when the form loads.
Meta-Knight
NumeicUpDown should be zero when it loads...because its the amount of seats required, the seats remaining is the seatA etc.
Elliott
Thank you :) got it
Elliott