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
  • 相关阅读:
    idea初始化配置
    常用网址
    linux改错了profile文件
    获得ip地址[转载]
    java 基本数据类型转换
    log4j配置概要
    HTTP状态码
    HTTP 的请求方式
    10、类和方法
    9、一切都是对象
  • 原文地址:https://www.cnblogs.com/Duiker/p/346228.html
Copyright © 2011-2022 走看看