|
Visual Basic (VB and VBA) |
|
Copyright 1999-2001 Christopher Greaves. All rights reserved. Home Page and email to [email protected] |
| If in doubt, record a macro and inspect the entrails! |
Please read the DISCLAIMER.
Here is an INDEX to all the procedures.
You will probably need one copy of my GLOBAL DECLARATIONS.
Public Function strIdentifier(strBodyLine As String) As String
' Procedure : strIdentifier
' Description: Parse the next available identifier from the given string.
' By: Chris Greaves Inc.
' Inputs: STRING
' Returns: STRING.
' Assumes: None.
' Side Effects: The line contents may be reduced.
' Tested: by the calls shown below.
''Use the following rules when you name procedures, constants, variables, and arguments in a Visual Basic module:
''
''· You must use a letter as the first character.
''· You can't use a space, period (.), exclamation mark (!), or the characters @, &, $, # in the name.
''· Name can't exceed 255 characters in length.
''· Generally, you shouldn't use any names that are the same as the functions, statements, and methods in Visual Basic. You end up shadowing the same keywords in the language. To use an intrinsic language function, statement, or method that conflicts with an assigned name, you must explicitly identify it. Precede the intrinsic function, statement, or method name with the name of the associated type library. For example, if you have a variable called Left, you can only invoke the Left function using VBA.Left.
''
''· You can't repeat names within the same level of scope. For example, you can't declare two variables named age within the same procedure. However, you can declare a private variable named age and a procedure-level variable named age within the same module.
''
''Note Visual Basic isn't case-sensitive, but it preserves the capitalization in the statement where the name is declared.
Dim strResult As String
strResult = strSplitStringAt(Trim(strBodyLine), " ", True) ' delimited at furthest by a space character
Dim strValidChars As String
strValidChars = strcAlpha & strcDigits & "_"
Dim intPosition As Integer
intPosition = 1
Do Until intPosition > Len(strResult)
If InStr(1, strValidChars, Mid$(strResult, intPosition, 1)) > 0 Then ' found a terminator
Else
strResult = Left$(strResult, intPosition - 1)
Exit Do
End If
intPosition = intPosition + 1
Loop
strBodyLine = Trim(Right(strBodyLine, Len(strBodyLine) - Len(strResult)))
strIdentifier = UCase(strResult)
'Sub TESTstrIdentifer()
'Dim strLine As String
'strLine = "() dim strAr() As String"
'While strLine <> ""
' MsgBox strIdentifier(strLine) & " | " & strLine
' While strLine <> "" And InStr(1, strcAlpha, Left$(strLine, 1)) = 0
' strLine = Right$(strLine, Len(strLine) - 1)
' Wend
'Wend
'End Sub
End Function
| We all knew nothing when we started … |
|
Home Page and Contact Information Send email to [email protected]. This page was last updated Thursday, November 15, 2001 |