Programmer 的進程 - 由 VB6 開始

Xojo / RealBasic 相關文件及程式庫 => Xojo / RealBasic 範例及函式庫 => Topic started by: admin on August 23, 2011, 07:46:46 PM

Title: 過濾 KeyDown事件的自訂函數
Post by: admin on August 23, 2011, 07:46:46 PM
Code: [Select]
Function FilterKeyDown(Key as string, optional tmpText as string,optional NoMinusSign as boolean=true,optional NoDecimal as boolean=false) As boolean
  dim tmpResult as boolean=true
  select case asc(key)
  case 48 to 57 'Number
    tmpResult=false
   
  case 8    'BackSpace
    tmpResult=false
   
  case 13   'Enter
    tmpResult=false
   
  case asc(".")
    if NoDecimal=false then
      if CheckCharExsit(key,tmptext)=false then
        tmpResult=false
      end if
    end if
   
  case asc("-")
    if NoMinusSign=false then
      if CheckCharExsit(key,tmptext)=false then
        tmpResult=false
      end if
    end if
   
  case 127  'Del
    tmpResult=false
   
  case 28 to 31  'Arrow Key
    tmpResult=false
   
  case 27    'Esc
    tmpResult=false
   
  end select
 
  Return tmpResult
End Function

Code: [Select]
Private Function CheckCharExsit(tmpChar As String,tmpText as string) As boolean
  Dim intX As Integer
  Dim tmpResult As Boolean=false
  if len(tmpText ) >0 then
    For intX = 1 To Len(tmpText)
      If tmpChar = Mid(tmpText, intX, 1) Then
        tmpResult = True
        Exit For
      End If
    next
  end if
 
  return tmpResult
 
End Function