Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Custom Function - "Is_NonAlpha" Post Reply Post New Topic
Author Message
Elizabeth_01
Newbie
Newbie


Joined: 22 Jul 2009
Location: United States
Online Status: Offline
Posts: 2
Quote Elizabeth_01 Replybullet Topic: Custom Function - "Is_NonAlpha"
     Posted: 22 Jul 2009 at 3:02pm
The lastname field in our DB is varchar and the software has no constraints. So although it is supposed to be alpha only (no symbols, no numbers), it isn't.

I am attempting to write a custom function in Crystal that will look at the string passed in and return true if the field is not purely alphabetical. I've tried this several ways and I must keep doing something wrong.

At this point, my function always returns false.

My function is below - any ideas? Thanks!

Function Is_NonAlpha(inString AS String) as Boolean
Dim n as Number
n = 1
Dim toReturn as Boolean
toReturn = false

For n = 1 to Len(inString)
    if Not((Mid(inString, n, 1) Like "[A-Za-z( )]")) then
       toReturn = true
    end if
Next

Is_NonAlpha = toReturn

End Function
Elizabeth
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 23 Jul 2009 at 6:47am
Does Crystal accept/process regular expressions?  I don't see anything in help about them.
 
If not, I would try:
   if instr("0123456789.,></?;:\|]}[{=+-_*&^%$#@!`~'",Mid(inString, n, 1))>0 then
       toReturn = true
    end if
 
you would still need to check for " which ascii 34...which can be checked using AscW(Mid(inString, n, 1)) =  34 then toReturn = true
 
HTH
IP IP Logged
Elizabeth_01
Newbie
Newbie


Joined: 22 Jul 2009
Location: United States
Online Status: Offline
Posts: 2
Quote Elizabeth_01 Replybullet Posted: 23 Jul 2009 at 8:31am
Great catch! Wasn't even thinking about regular expressions not being supported. Habit there.

It bothers me to actually hard code the non alpha characters, so I took your idea and inverted it. It works now! This is my new function:

Function Is_NonAlpha(inString AS String) as Boolean
Dim n as Number
n = 1
Dim toReturn as Boolean
toReturn = false

For n = 1 to Len(inString)
    Dim myChar as String
    myChar = UCase(Mid(inString, n, 1))
    Dim myAscii as Number
    myAscii = AscW(myChar)

    if myAscii < 65 or myAscii > 90 then
        toReturn = true
        exit For
    End If
Next

Is_NonAlpha = toReturn

End Function
Elizabeth
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 23 Jul 2009 at 10:03am

Yeah, that works...I'm not sure what I would have done, it was an off the top of my head....yeah, I agree hard coding is bad...you might miss something.

glad I could help
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum