Click here to Skip to main content
15,901,373 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
public tmr as integer

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    If Label1.Text = "10" Then Exit Sub
    For Each item As Object In Form2.ComboBox1.Items
        If comboresult = tmr Then
            Exit For
        End If
        Label1.Text = comboresult
        comboresult = item.ToString()
    Next
    tmr = Label1.Text
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    comboresult = Label1.Text
    If Label1.Text = "120" Then Exit Sub
    For Each item As Object In Form2.ComboBox1.Items
        If comboresult > tmr Then
            Exit For

        Else : comboresult = item.ToString()
        End If
    Next
    Label1.Text = comboresult
    tmr = Label1.Text
End Sub


'this will go backwards from start position and will move forward from anywhere but after pressing forward will not go backwards...grrr any insight will be appreciated.

[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 8-Apr-12 4:27am
v2

1 solution

In the Click event of Button3, the statements
VB
Label1.Text = comboresult
tmr = Label1.Text

make comboresult equal to tmr. So, after pressing the forward button, when the backward button is pressed, the following if condition in the Click event of Button2 will be true
VB
If comboresult = tmr Then
    Exit For
End If

hence, the backward logic may not be working after pressing the forward button.
 
Share this answer
 
Comments
tgebrael 10-Apr-12 10:26am    
That leaves me in the same place as now..is there not a attribute to the combobox object that will allow me to set a variable to the value of either the previous or next value in the combobox based on the currently selected value of the combobox...sorry for being such a newb.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900