推断输入信息是否为空
首先,推断窗口中全部文本框、组合框是否为空;
<span style="font-size:18px;">Imports System.Windows.Forms
'**********************************************
'文 件 名: verdict
'命名空间: UI
'内    容:
'功    能: 推断用户输入是否为空。推断输入的username等一系列是数字的文本框是否是数字
'文件关系:
'作    者:丁国华
'小    组:宝贝计划
'生成日期: 2014/8/5 10:32:09
'版本:V2.0
'改动日志:
'版权说明:
'**********************************************
Public Class verdict
    ''' <summary>
    ''' 推断窗口中全部文本框、组合框输入内容是否为空,若窗口中有同意为空的文本框或组合框,  
    '''则不能使用此函数 
    ''' </summary>
    ''' <param name="frm"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function IsAllEmptyText(ByVal frm As Form) As Boolean
        Dim control As New Control
        For Each control In frm.Controls '遍历窗口中全部的控件  
            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 True
                    Exit Function
                End If
            End If
        Next
        Return False
    End Function</span>
        接着。推断一部分文本框、组合框是否为空;
<span style="font-size:18px;"> ''' <summary>
    ''' 推断控件数组中的控件的Text属性是否为空  
    ''' </summary>
    ''' <param name="arrayControl"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared 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 True
                    Exit Function
                End If
            End If
        Next
        Return False
    End Function</span>          最后,推断是否为数字;
<span style="font-size:18px;"> ''' <summary>
    ''' 推断输入的是否为数字
    ''' </summary>
    ''' <param name="arrayControl"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function IsNumberic(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 '推断文本框内容是否为空  
                If IsNumeric(control.Text) = False Then
                    'MsgBox(control.Tag.ToString + "不能为空!", vbOKOnly, "温馨提示")
                    MsgBox(control.Tag.ToString + "   " + "请输入数字", vbOKOnly, "提示")
                    control.Focus()
                    control.Text = ""
                    Return False
                    Exit Function
                End If
            End If
        Next
        Return True
    End Function</span>
         紧接着,我们以机房收费系统中,基本数据设定为例,看看我们是怎样进行调用的;
<span style="font-size:18px;">        Dim arrayControl() As Control
        ReDim Preserve arrayControl(4)
        arrayControl(0) = txtRate
        arrayControl(1) = txtUnittime
        arrayControl(2) = txtLeasttime
        arrayControl(3) = txtPretime
        arrayControl(4) = txtLimitcash
        If verdict.IsSomeEmptyText(arrayControl) Then
            Exit Sub
        End If
        If verdict.IsNumberic(arrayControl) = False Then
            Exit Sub
        End If</span>         把公共须要使用的部分,抽象出来写成一个类,其余的窗口直接进行调用。这样方便,简单。第二版机房收费系统。未完。待续......
 
                    
                
 
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号