如果没有在文本框中输入任何内容,如何将默认值设置为零?
If TextBox1.Text = "" Then
TextBox1.Text = 0
End If
If TextBox2.Text = "" Then
TextBox2.Text = 0
End If
答案 0 :(得分:4)
您无法将.Text
的{{1}}属性设置为值0,因为它是System.Windows.Forms.TextBox
值类型。但是,您可以将其设置为String
的字符串表示形式0
。
"0"
如果您要设置Private Sub TextBox_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged, TextBox2.TextChanged
Dim txtBox As TextBox = DirectCast(sender, TextBox)
If String.IsNullOrEmpty(txtBox.Text) Then txtBox.Text = CStr(0)
End Sub
,那么在尝试将Option Strict On
属性设置为整数时会出错。
答案 1 :(得分:0)
不确定您的上下文或您尝试的内容,但您可以在Save / Capture / Next或任何按钮上尝试类似的内容。
If Trim(TextBox1.Text) = "" Then MyIntegerVariable = 0