View Single Post
Old 19-05-2010, 19:32
runflacruiser's Avatar
runflacruiser runflacruiser is offline
Senior Member
Join Date: Jun 2009
Location: Pigeon Forge, TN USA
Posts: 811

HI Shelby.
Oops, Cause I typed that example in the forum box, not copy and pasted from actual code.

Here's the sub (soon to be function.)
I'm guessing you'll know what it's for.
I want to validate a string beginning with a specified range of letters, and set and ultimately return the boolean.

Just in case you know a shorter, faster way, I'd love to hear it. It works fine, I think. I haven't really tested because the left function not working in this module is bugging

Str function?

Option Explicit

Sub test()

End Sub
Sub letterPass()
    'soon to be a function ' ()as boolean
    Dim fontName As String, startLet As String, endLet As String
    Dim abcArr As Variant
    Dim letter As String
    Dim startKey As Long, endKey As Long
    Dim pass As Boolean
    Dim i As Integer, j As Integer, k As Integer
    pass = False 'flag set
    startLet = "@": endLet = "0"
    fontName = "@try"

    letter = Left(fontName, 1) 'not working...hmmmmmm
    'letter = "@" 'for testing
    'may move array outside function for more speed. This is for now.
    abcArr = Split("@ # ! ? ( ) * . 0 1 2 3 4 5 6 7 8 9 0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z")

    'get start key
    For i = 0 To UBound(abcArr)
       If abcArr(i) = startLet Then startKey = i
    Next i
    'get end key if set. This will be an optional param of the function.
    If endLet <> "" Then
        For j = 0 To UBound(abcArr)
           If abcArr(j) = endLet Then endKey = j
        Next j
        endKey = startKey
    End If
    'check fontname against each first letter value in range
    For k = startKey To endKey
        If UCase(letter) = abcArr(k) Or LCase(letter) = abcArr(k) Then pass = True
    Next k
    MsgBox pass 'is the fname inbetween the specified letter range
End Sub
Reply With Quote