I work for a lab and I am writing a huge program. As part of this, I have a simple text box where the user can put in a sample number, say w2484 or what ever they want. Right beside it I have a vscrollbar to increment or decrement the value in the text box. I am taking over and finishing the program started by someone else too. (Oh boy I am lucky!) The Sub below, the first part is commented out because it would not work, but I did not want to delete it. I can increment and decrement the sample number some times, but sometimes it would not go up or down for what ever reason. So I tried the second select case with the following results:
It executes twice so my sample numbers count by two not one. If I press the 'down button, eventArgs.Type comes in as SmallIncrement, which is backwards from what I would think since I pressed the down button, and the same is true if I press the up button, eventArgs.Type comes in as SmallDecrement, which once again is backwards I think. It executes the second time because eventArgs.Type is EndScroll.
For eventArgs.NewValue I am getting 0 if I press the up button, and 1 if I press the down button
Private Sub vscrSampleNumber_Scroll(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.ScrollEventArgs) Handles vscrSampleNumber.Scroll
'Select Case eventArgs.Type
' Case System.Windows.Forms.ScrollEventType.EndScroll
' vscrSampleNumber_Change(eventArgs.NewValue)
'End Select
Select eventArgs.Type
Case System.Windows.Forms.ScrollEventType.ThumbTrack
vscrSampleNumber_Change(eventArgs.NewValue)
Case System.Windows.Forms.ScrollEventType.SmallIncrement
vscrSampleNumber_Change(eventArgs.NewValue)
Case System.Windows.Forms.ScrollEventType.SmallDecrement
vscrSampleNumber_Change(eventArgs.NewValue)
Case System.Windows.Forms.ScrollEventType.EndScroll
vscrSampleNumber_Change(eventArgs.NewValue)
End Select
End Sub
Private Sub vscrSampleNumber_Change(ByVal newScrollValue As Integer)
Dim temp As String
temp = txtSampleNumber.Text 'Cannot pass a control
If newScrollValue = 0 Then ' if up was pressed
txtSampleNumber.Text = Increment_Sample_Number(temp)
ElseIf newScrollValue = 1 Then ' if down was pressed
txtSampleNumber.Text = Decrement_Sample_Number(temp)
End If
End Sub
It executes twice so my sample numbers count by two not one. If I press the 'down button, eventArgs.Type comes in as SmallIncrement, which is backwards from what I would think since I pressed the down button, and the same is true if I press the up button, eventArgs.Type comes in as SmallDecrement, which once again is backwards I think. It executes the second time because eventArgs.Type is EndScroll.
For eventArgs.NewValue I am getting 0 if I press the up button, and 1 if I press the down button
Private Sub vscrSampleNumber_Scroll(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.ScrollEventArgs) Handles vscrSampleNumber.Scroll
'Select Case eventArgs.Type
' Case System.Windows.Forms.ScrollEventType.EndScroll
' vscrSampleNumber_Change(eventArgs.NewValue)
'End Select
Select eventArgs.Type
Case System.Windows.Forms.ScrollEventType.ThumbTrack
vscrSampleNumber_Change(eventArgs.NewValue)
Case System.Windows.Forms.ScrollEventType.SmallIncrement
vscrSampleNumber_Change(eventArgs.NewValue)
Case System.Windows.Forms.ScrollEventType.SmallDecrement
vscrSampleNumber_Change(eventArgs.NewValue)
Case System.Windows.Forms.ScrollEventType.EndScroll
vscrSampleNumber_Change(eventArgs.NewValue)
End Select
End Sub
Private Sub vscrSampleNumber_Change(ByVal newScrollValue As Integer)
Dim temp As String
temp = txtSampleNumber.Text 'Cannot pass a control
If newScrollValue = 0 Then ' if up was pressed
txtSampleNumber.Text = Increment_Sample_Number(temp)
ElseIf newScrollValue = 1 Then ' if down was pressed
txtSampleNumber.Text = Decrement_Sample_Number(temp)
End If
End Sub