会员登录 - 用户注册 - 网站地图 Office中国(office-cn.net),专业Office论坛
当前位置:主页 > 源码 > Access源码示例 > 经典算法 > 正文

Access限制录入不同类型的数据

时间:2013-12-11 15:56 来源:office中国 作者:andymark 阅读:
软件类型:国产软件 授权方式:免费软件 界面语言:简体中文 软件大小:95.1 KB 文件类型:.rar 运行环境:Win2003,WinXP,Win7,win8 软件等级:★★★★★ 发布时间:2013-12-11 插件情况:无插件,请放心使用。 下载次数:
软件介绍:
    我们做的应用程序很多时候都会限制数据录入的类型,比如说购买数量,我们不能随便输入文字,更不能输入负数和小数了。这时我们当然要限制其输入了,否则就会出错。
    下面的示例是使用了类模块创建函数,方便调用限制不规则的录入。可以设置整数格式,小数格式,字符格式,email格式,电话格式等。
    自己还可以根据自己的需要,改写符合自己需要的格式。达到控制文本的录入,尽量减少由于输入不规范带来的影响



 Private m_DataType As Integer   '定义数据类型
 Private WithEvents LimitTextBox As TextBox
 
 Enum DType
    MyChar = 0     '字符类型
    MyInt = 1      '整数
    MyDecimal = 2  '小数
    MyPhone = 3    '电话
    MyEmail = 4    'Email
    MyNone = 5     '常规
End Enum
 
 
Property Get DataType() As DType
    DataType = m_DataType
End Property
 
Property Let DataType(Value As DType)
    m_DataType = Value
End Property
 
Public Sub SetTextBoxType(LimitText As TextBox, LimitType As DType)
  '设置文本数据类型
    Set LimitTextBox = LimitText
    With LimitTextBox
        DataType = LimitType
       .OnKeyPress = "[Event Procedure]"
    End With
  
End Sub
Private Sub LimitTextBox_KeyPress(KeyAscii As Integer)
   
   Select Case m_DataType
      
      Case 0
         If Not IsChar(KeyAscii) = True Then KeyAscii = 0
      Case 1
          If Not IsInt(KeyAscii) = True Then KeyAscii = 0
      Case 2
          If Not IsDecimal(KeyAscii) = True Then KeyAscii = 0
      Case 3
           If Not IsPhone(KeyAscii) = True Then KeyAscii = 0
      Case 4
           If Not IsEmail(KeyAscii) = True Then KeyAscii = 0
      Case 5
          
    End Select
 
End Sub
 
 
Private Sub Class_Initialize()
    Set LimitTextBox = Nothing
End Sub
 
 
Private Function IsChar(ByVal A As Integer) As Boolean
    If (A < 97 Or A > 122) And (A < 65 Or A > 90) And (A <> 8) And (A <> 32) Then
        IsChar = False
       Else
        IsChar = True
    End If
End Function
Private Function IsInt(ByVal A As Integer) As Boolean
    If (A < 48 Or A > 57) And (A <> 8) Then
       
          IsInt = False
       Else
          IsInt = True
    End If
End Function
    
Private Function IsDecimal(ByVal KeyAscii As Integer) As Boolean
    If (KeyAscii >= 48 And KeyAscii <= 57) Or KeyAscii = 8 Or KeyAscii = Asc(".") Then
        IsDecimal = True
     Else
        IsDecimal = False
    End If
End Function
Private Function IsPhone(ByVal A As Integer) As Boolean
    If (A < 48 Or A > 57) And (A <> 8) And (A <> Asc("-")) Then
        IsPhone = False
       Else
        IsPhone = True
    End If
End Function
Private Function IsEmail(ByVal A As Integer) As Boolean
    If (A < 97 Or A > 122) And (A < 65 Or A > 90) And (A <> 8) And (A < 48 Or A > 57) And A <> Asc("-") And A <> Asc("@") And A <> Asc(".") Then
        IsEmail = False
       Else
        IsEmail = True
    End If
End Function
Private Function IsProperDecimal(ByVal No As String) As Boolean
    Dim NoLen
    Dim DotFlag
    DotFlag = 0
 
    NoLen = Len(No)
    Dim I As Integer
    For I = 1 To NoLen
        If Mid(No, I, 1) = "." Then DotFlag = DotFlag + 1
    Next I
    If DotFlag > 1 Then IsProperDecimal = False Else IsProperDecimal = True
End Function
 
 

顶一下
(2)
100%
踩一下
(0)
0%
下载地址:
注意事项:

☉推荐使用第三方专业下载工具下载本站软件,使用 WinRAR v3.10 以上版本解压本站软件。
☉如果这个软件总是不能下载的请点击报告错误,谢谢合作!!
☉下载本站资源,如果服务器暂不能下载请过一段时间重试!
☉如果遇到什么问题,请到本站论坛去咨寻,我们将在那里提供更多 、更好的资源!
☉本站提供的一些商业软件是供学习研究之用,如用于商业用途,请购买正版。

发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价: