Atlanta Custom Software Development 

   Search        Code/Page

User Login



Forgot the Password?
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
» Regular Expr Tester
» Free Tools

ValidateVBName - Check a variable's or procedure's name
[ All Languages » VB »  AddIn]

Total Hit ( 1530)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article



Click here to copy the following block
' Return True if a string is a valid name for a Visual Basic variable or
' procedure.
' This function turns to be useful when writing add-ins that generate code.
' The optional arguments specify whether type-declaration characters (%,&,!,#,@,
' and $)
' should be considered as valid, and whether the dot character is accepted.

Function ValidateVBName(ByVal VBName As String, Optional ByVal acceptTypeChars _
  As Boolean, Optional ByVal acceptDots As Boolean) As Boolean
  Dim i As Long
  ' reject null strings or strings that are too long
  If Len(VBName) = 0 Or Len(VBName) > 255 Then Exit Function
  ' check each character
  For i = 1 To Len(VBName)
    Select Case Asc(Mid$(VBName, i, 1))
      Case 65 To 90, 97 To 122
        ' alphabetic chars
      Case 48 To 57, 95
        ' digits and underscore, only good if not firs character
        If i = 1 Then Exit Function
      Case 37, 38, 33, 35, 64, 36
        ' type declaration characters
        If i < Len(VBName) Or Not acceptTypeChars Then Exit Function
      Case 46
        ' dot
        If i = 1 Or Not acceptDots Then Exit Function
      Case Else
        Exit Function
    End Select
  ' all tests passed
  ValidateVBName = True
End Function

Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with, SQL Server and other MS technologies. He is, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )

Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.