推断文本框是否为空
在窗口上往往有非常多文本框须要输入信息,一些下拉框须要选择,对于这些信息的输入,我们总是须要推断输入的是否为空。曾经,总是一个一个的推断。这样太繁琐。也可能会丢掉当中的一个两个的。
如今就让我们轻松解决推断文本框是否为空吧。
<span style="font-size:18px;">''' <summary> ''' 用来推断文本框和下拉框是否为空 ''' </summary> ''' <remarks></remarks> 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 </span>
<span style="font-size:18px;">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</span>
注意:
<span style="font-size:18px;"> MsgBox(control.Tag.ToString + "不能为空", vbOKOnly, "温馨提示")</span>当中的 Tag 属性往往忘记赋值。通常赋值为文本框前面的label.text