會(huì)員登錄 - 用戶注冊(cè) - 網(wǎng)站地圖 Office中國(guó)(office-cn.net),專業(yè)Office論壇
當(dāng)前位置:主頁 > 源碼 > Access源碼示例 > 經(jīng)典算法 > 正文

Access限制錄入不同類型的數(shù)據(jù)

時(shí)間:2013-12-11 15:56 來源:office中國(guó) 作者:andymark 閱讀:
軟件類型:國(guó)產(chǎn)軟件 授權(quán)方式:免費(fèi)軟件 界面語言:簡(jiǎn)體中文 軟件大。95.1 KB 文件類型:.rar 運(yùn)行環(huán)境:Win2003,WinXP,Win7,win8 軟件等級(jí):★★★★★ 發(fā)布時(shí)間:2013-12-11 插件情況:無插件,請(qǐng)放心使用。 下載次數(shù):
軟件介紹:
    我們做的應(yīng)用程序很多時(shí)候都會(huì)限制數(shù)據(jù)錄入的類型,比如說購(gòu)買數(shù)量,我們不能隨便輸入文字,更不能輸入負(fù)數(shù)和小數(shù)了。這時(shí)我們當(dāng)然要限制其輸入了,否則就會(huì)出錯(cuò)。
    下面的示例是使用了類模塊創(chuàng)建函數(shù),方便調(diào)用限制不規(guī)則的錄入?梢栽O(shè)置整數(shù)格式,小數(shù)格式,字符格式,email格式,電話格式等。
    自己還可以根據(jù)自己的需要,改寫符合自己需要的格式。達(dá)到控制文本的錄入,盡量減少由于輸入不規(guī)范帶來的影響



 Private m_DataType As Integer   '定義數(shù)據(jù)類型
 Private WithEvents LimitTextBox As TextBox
 
 Enum DType
    MyChar = 0     '字符類型
    MyInt = 1      '整數(shù)
    MyDecimal = 2  '小數(shù)
    MyPhone = 3    '電話
    MyEmail = 4    'Email
    MyNone = 5     '常規(guī)
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)
  '設(shè)置文本數(shù)據(jù)類型
    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%
下載地址:
注意事項(xiàng):

☉推薦使用第三方專業(yè)下載工具下載本站軟件,使用 WinRAR v3.10 以上版本解壓本站軟件。
☉如果這個(gè)軟件總是不能下載的請(qǐng)點(diǎn)擊報(bào)告錯(cuò)誤,謝謝合作!!
☉下載本站資源,如果服務(wù)器暫不能下載請(qǐng)過一段時(shí)間重試!
☉如果遇到什么問題,請(qǐng)到本站論壇去咨尋,我們將在那里提供更多 、更好的資源!
☉本站提供的一些商業(yè)軟件是供學(xué)習(xí)研究之用,如用于商業(yè)用途,請(qǐng)購(gòu)買正版。

發(fā)表評(píng)論
請(qǐng)自覺遵守互聯(lián)網(wǎng)相關(guān)的政策法規(guī),嚴(yán)禁發(fā)布色情、暴力、反動(dòng)的言論。
評(píng)價(jià):