0

我有一个带有加号和减号按钮的计算器,上面有这个代码

    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

但是,当单击按钮时文本框中的数字超过 3 位时,我想让文本框根据需要删除尽可能多的数字,以便文本框中有 3 位数字有帮助吗?

语言是visual basic 2010

4

2 回答 2

1

你可以这样做:

TextBox1.Text = TextBox1.Text.Substring(0, 3);
于 2013-10-10T11:19:00.533 回答
0

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

于 2013-10-22T14:34:33.947 回答