zoukankan      html  css  js  c++  java
  • 重构代码-随笔(1)


    原始代码:
        If txtSchool.Text = "" Then
            
    MsgBox "请输入注册单位!", vbInformation
            CheckRegText 
    = False
            txtSchool.SetFocus
            
    Exit Function
        
    End If

    1:len(txtSchool.Text)  要比 txtSchool.Text=""快的多。

    2:为txtSchool.Text加上Trim

    3:去除txtSchool的重复。

    结果:

    1:StringIsEmpty函数
    '判断字符串的长度是否为空
    Public Function StringIsEmpty(ByRef sString As StringAs Boolean
        sString 
    = Trim(sString)
        StringIsEmpty 
    = Len(sString) = 0
    End Function

    2:TextBoxIsEmpty函数
    '文本框为空
    Private Function TextBoxIsEmpty(oTextBox As TextBox, sMessage As String) AS Boolean
        
    If StringIsEmpty(oTextBox.Text) Then
            
    MsgBox sMessage, vbInformation
            oTextBox.SetFocus
            TextBoxIsEmpty 
    = True
        
    End If
    End Function

    3:最终效果
        If TextBoxIsEmpty(txtPerson, "请输入注册人!"Then Exit Function
        
        
    If TextBoxIsEmpty(txtConn, "请输入联系电话!"Then Exit Function
        
        
    If TextBoxIsEmpty(txtSchool, "请输入注册单位!"Then Exit Function
  • 相关阅读:
    Python 标准库 urllib2 的使用细节
    为什么C++编译器不能支持对模板的分离式编译
    source insight插件
    tar命令
    绘制和重绘,有效矩形和无效矩形
    常量表达式
    区间迭代
    lambda函数
    decltype和新的返回值语法
    auto用法
  • 原文地址:https://www.cnblogs.com/Duiker/p/346228.html
Copyright © 2011-2022 走看看