Source code for Issue Number 33

Copyright 1997-2000 by C&D Programming Corp. All Rights Reserved. Source code may not be reproduced except for use in a compiled executable. All rights reserved. If you would like to reprint any or all of this code please email us at info@codeoftheweek.com

Code of the Week Home


Source Code

Just paste this code into a new module and change the name of the module to basValidation.

'----------------------------------------------------------------------
'
'   Module Name:    basValidation
'   Written By:     C&D Programming Corp.
'   Create Date:    4/98
'   Copyright:      Copyright 1998 by C&D Programming Corp.  Source
'                   code may not be reproduced except for use in a
'                   compiled executable.  All rights reserved.  If
'                   you would like to reprint any or all of this
'                   code please email us at info@codeoftheweek.com
'----------------------------------------------------------------------
Option Explicit

'
'   This subroutine is designed to be used in a KeyDown or
'   KeyPress event.
'
'   It will return TRUE if the key is a letter key.  This
'   function only works for software written in the U.S.
'
'   To make this function work for VB 3, just change the return
'   value to Integer.
'
Function IsAlphaKey(KeyAscii As Integer) As Boolean
    IsAlphaKey = (KeyAscii >= Asc("A") And KeyAscii <= Asc("Z")) Or _
                 (KeyAscii >= Asc("a") And KeyAscii <= Asc("z"))
End Function

'
'   This subroutine is designed to be used in a KeyDown or
'   KeyPress event.
'
'   It will return TRUE if the key is a letter key.  This
'   function only works for software written in the U.S.
'
'   To make this function work for VB 3, just change the return
'   value to Integer.
'
Function IsAlphaNumericKey(KeyAscii As Integer) As Boolean
    IsAlphaNumericKey = IsAlphaKey(KeyAscii) Or IsNumericKey(KeyAscii)
End Function

'
'   This subroutine is designed to be used in a KeyDown or
'   KeyPress event.
'
'   It will return TRUE if the key is a letter key.  This
'   function only works for software written in the U.S.
'
'   To make this function work for VB 3, just change the return
'   value to Integer.
'
Function IsEditingKey(KeyAscii As Integer) As Boolean
    IsEditingKey = (KeyAscii = vbKeyBack)
End Function

'
'   This subroutine is designed to be used in a KeyDown or
'   KeyPress event.
'
'   It will return TRUE if the key is a numeric key.  This includes
'   negative signs and decimals or commas.
'
'   To make this function work for VB 3, just change the return
'   value to Integer.
'
Function IsNumericKey(KeyAscii As Integer) As Boolean
    IsNumericKey = (KeyAscii >= Asc("0") And KeyAscii <= Asc("9")) Or _
                   (KeyAscii = Asc(".")) Or (KeyAscii = Asc("-")) Or _
                   (KeyAscii = Asc(","))
End Function