Reputation:
I have a calculator with the plus and minus buttons having this code
If TextBox1.Text.Length > 3 And TextBox1.Text.Length < 999999 Then
MsgBox("You can't add any more numbers!")
TextBox1.Text = TextBox1.Text.Remove(TextBox1.Text.Length - 1, 1)
Else
int_number1 = TextBox1.Text
TextBox1.Text = ""
Bln_Plus = False
Bln_Minus = True
However, when there is more than 3 digits in the textbox when the button is clicked I want to make the textbox remove as many digits as it needs so there is 3 digits in the textbox Any help??
The language is visual basic 2010
Upvotes: 0
Views: 1247
Reputation: 1
Actually all you really need to do is alter your range.
If TextBox1.Text.Length > 3 And TextBox1.Text.Length < 999999 Then
MsgBox("You can't add any more numbers!")
TextBox1.Text = TextBox1.Text.Remove(TextBox1.Text.Length - 3, 999999)
Else
int_number1 = TextBox1.Text
TextBox1.Text = ""
Bln_Plus = False
Bln_Minus = True
Hope this helped
Upvotes: 0
Reputation: 1571
You can do something like this:
TextBox1.Text = TextBox1.Text.Substring(0, 3);
Upvotes: 1