Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 如果textbox有字符串,则显示msgbox,但(.)不起作用。visual basic_Vb.net - Fatal编程技术网

Vb.net 如果textbox有字符串,则显示msgbox,但(.)不起作用。visual basic

Vb.net 如果textbox有字符串,则显示msgbox,但(.)不起作用。visual basic,vb.net,Vb.net,我有这个文本框,我只想输入(.)包含的数字。例如,它是190.5 但是如果它有文本,例如190.5g,那么它将显示msgbox(“错误”) 我在某处找到了这个密码 Dim allDigit = pbox.Text.Trim.Length <> 0 AndAlso _ pbox.Text.All(Function(chr) Char.IsDigit(chr)) If Not allDigit Then MsgBox("Please

我有这个文本框,我只想输入(.)包含的数字。例如,它是190.5

但是如果它有文本,例如190.5g,那么它将显示msgbox(“错误”)

我在某处找到了这个密码

 Dim allDigit = pbox.Text.Trim.Length <> 0 AndAlso _
      pbox.Text.All(Function(chr) Char.IsDigit(chr))
        If Not allDigit Then
            MsgBox("Please input number only on price")
            pbox.Clear()
            Exit Sub
        End If
Dim allDigit=pbox.Text.Trim.Length 0 AndAlso_
pbox.Text.All(函数(chr)字符IsDigit(chr))
如果不是全部数字,那么
MsgBox(“请仅在价格上输入数字”)
pbox.Clear()
出口接头
如果结束
如果我加上。在数字上,它显示了msgbox,因此是否仍有包含的

检查一下,而不是自己把绳子拉开

Dim value As Decimal
Dim yourString As String = "1234"
If Not Decimal.TryParse(yourString, value) Then
    MsgBox("Please input number only on price")
    pbox.Clear()
    Exit Sub
End If
需要注意的是,代表小数点分隔符的字符将根据操作系统的语言设置而有所不同-对于美式/英式英语,它将是句点,对于德语,它将是逗号。

使用函数代替

    If Not IsNumeric(pbox.Text) Then
        MsgBox("Please input number only on price")
        pbox.Clear()
        Exit Sub
    End If
这是我使用的c语言代码

    private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (!char.IsControl(e.KeyChar) 
            && !char.IsDigit(e.KeyChar) 
            && e.KeyChar != '.')
        {
                            //message box
            e.Handled = true;
        }

        // only allow one decimal point
        if (e.KeyChar == '.' 
            && (sender as TextBox).Text.IndexOf('.') > -1)
        {
                            //message box
            e.Handled = true;
        }
    }

我不知道如何使用它。我只是从某个地方得到了代码,所以我不知道它是如何工作的。@BillyOtsuka-已经添加了一个示例。