I agree on that:)Let's see If I understand:
You have a ComboBox control named ComboBox1. It have two states:
State 1: "0 to 1.0"
State 2: "0 to 10.0"
I guess that you want to limit the TrackBar1 between "0 to 1.0", or "0 to 10", in agreement with your ComboBox1 strings (State 1 or State 2).
the problem is that your TrackBar1 can take values between 0 and 1000, AND, it only can have INTEGER values.
Your TrackBar1 can take those values: 0, 1, 2, 3, ... ,1000.
a-You want to write a value in your TextBox, then push the Button1, and the program must set the TrackBar1 value between "0 to 1" or "0 to 10". But since the trackBar really varies between 0 to 1000, you want to work it some way.
b-If the text on TextBox.Text is invalid, then you want to Warning the user that his value is not allowed.
That is what I guess.
Warning 1: Never name a TextBox "TextBox". Name it "TextBox1", "MyTextBox", or "TheTextBoxThatSetsTheTrackBar".
If you name it "TextBox", VB.NET does not know if you want to use THAT TextBox, or ANY TextBox. It would do weird things.
Now, let's go:
0-Double click your "TextBox". You gonna go to
Code:
Private Sub Textbox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Textbox.TextChanged
Test5()
End Sub
Right click on test5() line, and choose "Go to Definition", You gonna get "Sub Test5()", you Sub routine that runs each time you change the text of "TextBox".
1-The first thing you need to do is check If that TextBox.Text is a number, because the bratty User may have written anything (like ":-P").
2-If is a number, then, you need to check if it is limited in agreement with the bounds on ComboBox1.
4-If there are a problem, then you need to gently kick the user asss.
5-If not was a problem, then you gonna set the TrackBar1.Value
__5.1-Calculating the value to set:
____5.1.1 Convert between "0 to 1" (OR "0 to 10") to "0 to 1000".
____5.1.2 Update that value on TrackBar1.Value
Now, lets see what you have writen:
Code:
If Form2.Combobox1.SelectedItem = "0 to 1.0" Then
If Form2.Textbox.Text >= 1.1 And Form2.Textbox.Text <= 10.0 Then
MessageBox.ShowDialog()
End If
If Val(Form2.Textbox.Text) <= 999 Then
Form2.TrackBar1.Value = Val(Form2.Textbox.Text)
End If
If Form2.TrackBar1.Value = 1000 Then
Form2.Textbox.Text = "1.0"
End If
End If
1-it did not check if it is a number
2-Then, it check if the value is licitous, and Kick the poor User when 1.1<=TextBox.Text<=1.0!... Take it!, User
3-After that, it updates TrackBar1 if TextBoxtext1.Text is <=999. So, if TextBoxtext1.Text="-1000000"....
4-Then, if TrackBar1.Value = 1000 , then, it writes againt the TextBox, but that is writting to a TextBox; TATH runs again "Private Sub Textbox_TextChanged", so it run again "Sub Test5()"...
I are short on time, so, I give you:
Code:
Sub Test5()
If Not IsNumeric(Form2.Textbox.Text) Then
'Kick User here
Else
Select Case Form2.Combobox1.SelectedItem.ToString
Case "0 to 1.0"
If Val(Form2.Textbox.Text) >= 0 And Val(Form2.Textbox.Text) <= 1 Then 'All rigth? Update trackBar1
Form2.TrackBar1.Value = 1000 * Val(Form2.Textbox.Text)
Else
MessageBox.ShowDialog() 'Not Right?. User Kick
End If
Case "0 to 10.0"
If Val(Form2.Textbox.Text) >= 0 And Val(Form2.Textbox.Text) <= 10 Then 'All rigth? Update trackBar1
Form2.TrackBar1.Value = 100 * Val(Form2.Textbox.Text)
Else
MessageBox.ShowDialog() 'Not Right?. User Kick
End If
End Select 'Form2.Combobox1.SelectedItem.ToString
End If 'Not IsNumeric
End Sub 'Test5
I hope you go crazy like Seal:ehh:.