Author Topic: 過濾 KeyDown事件的自訂函數  (Read 4413 times)

admin

  • Administrator
  • *****
  • Posts: 0
    • View Profile
過濾 KeyDown事件的自訂函數
« 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
« Last Edit: October 23, 2011, 01:47:01 AM by Roy Chan »