Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Case Sensitive If Statment? 1

Status
Not open for further replies.

Golfnit

Technical User
Feb 20, 2002
5
0
0
US

Hello Group,

Crystal 8, strait-up database

Trying to get the If statment to detect a difference in case. See the formula field below for code.

-------- Originator Formula Field ----------
Local stringVar LocalTemp := Right((Trim({CLIENT.ClientType2})),1);

if LocalTemp = "A" then LocalTemp := "DRH";
if LocalTemp = "a" then LocalTemp := "TCG";
...
LocalTemp
--------------------------------------------

Is there a way for the answer to be DRH and not TCG?

Thanks
Scott
 
I had always thought that crystal made it's comparisons case-sensitive but as you point out this is not the case...which makes you wonder what the heck is the usefulness of the Uppercase and Lowercase functons :)

my solution to this is to wrap both sides of the comparison with the function ASC() which will force it to campare the ascII values

so try this

if asc(Localtemp) = asc("A") then LocalTemp := "DRH";
if asc(Localtemp) = asc("a") then LocalTemp := "TCG";

that should work...

Jim
JimBroadbent@Hotmail.com
 
Apparently the setting in Report - Options that says "Case Insensitive SQL data" also affects the case sensitivity of formulas. That surprises me, because I don't think that was always the case. Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
I think this lack of case sensitivity sort of crept in at some point....I recall in CR5 anyway always having to bulletproof my parameter inputs by forcing them to uppercase for testing...it appears I don't have to do that anymore.... Jim
JimBroadbent@Hotmail.com
 
Thanks for your responses!

I tried the solution from Ngolem but didn’t work for every condition. It somehow still had problems comparing the ASCII numbers. But I was determined this is the way out, so I changed the if statements up a little bit and now it works great! See below:

-------------- Originator Formula Field ----------------

Local NumberVar NumTemp := Asc(Right((Trim({CLIENT.ClientType2})),1));
Local StringVar StrTemp := "";

if NumTemp = 65 then StrTemp := "DRH"; //UpperCase A
if NumTemp = 97 then StrTemp := "TCG"; //LowerCase a


StrTemp

--------------------------------------------------------

I am not sure why Ngolem’s suggestion did not work, in theory it was rock solid, but in practice something was not right. Still wondering about that one... Maybe Seagate will have an option for case comparison in later versions.

Thanks everyone!
Scott
 
I think it is with multiple characters in a string it only performs the ASC() on the first character

Thanks for correcting it Jim
JimBroadbent@Hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top