判断文本框是否为空
在窗体上往往有很多文本框需要输入信息,一些下拉框需要选择,对于这些信息的输入,我们总是需要判断输入的是否为空,以前,总是一个一个的判断,这样太繁琐,也可能会丢掉其中的一个两个的。现在就让我们轻松解决判断文本框是否为空吧。
''' ''' 用来判断文本框和下拉框是否为空
'''
'''
Module Module1
Public Function IsSomeEmptyText(ByVal arrayControl() As Control) As Boolean
Dim control As New Control
For Each control In arrayControl '遍历数组中的所有元素
If TypeOf control Is TextBox Then '判断控件是不是文本框
If control.Text.Trim = "" Then '判断文本框内容是不是为空
MsgBox(control.Tag.ToString + "不能为空", vbOKOnly, "温馨提示")
control.Focus()
Return True
Exit Function
End If
ElseIf TypeOf control Is ComboBox Then '判断控件是不是组合框
If control.Text.Trim = "" Then
MsgBox(control.Tag.ToString + "不能为空!", vbOKOnly, "温馨提示")
Return False
Exit Function
End If
End If
Next
Return False
End Function
End Module
调用函数:
Dim arrayControl() As Control
ReDim Preserve arrayControl(5)
arrayControl(0) = txtHourRate
arrayControl(1) = txtHourTmpRate
arrayControl(2) = txtLeastTime
arrayControl(3) = txtLeastM
arrayControl(4) = txtIncreaseTime
arrayControl(5) = txtPrepareTime
If IsSomeEmptyText(arrayControl) Then
Exit Sub
End If
注意:MsgBox(control.Tag.ToString + "不能为空", vbOKOnly, "温馨提示")
其中的 Tag 属性往往忘记赋值,通常赋值为文本框前面的label.text
http://www.dengb.com/Javabc/849763.htmlwww.dengb.comtruehttp://www.dengb.com/Javabc/849763.htmlTechArticle判断文本框是否为空 在窗体上往往有很多文本框需要输入信息,一些下拉框需要选择,对于这些信息的输入,我们总是需要判断输入的是否...