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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If Asc function returns Boolean value instead of number string

Status
Not open for further replies.

NRGman

Programmer
Aug 17, 2001
5
US
The below formula, copied off Crystal Decisions website (and customized)returns a Boolean value instead of the expected numeric string.

NumberVar i;
stringVar outputcur := "";
//NumberVar finalcur:=0;

For i:=1 To Length({@Current Year's YTD Calculation}) Do
If Asc({@Current Year's YTD Calculation}) In 48 To 57 Then
outputcur:=outputcur+{@Current Year's YTD Calculation};
// finalcur:=tonumber(outputcur);

'Commenting out (//)' the 3rd and last lines was the only thing that enabled me to determine that Boolean values were being returned.

Any explanation or alternative strategy would be appreciated.
 
Your variable name is getting being read as an italics flag by the TT forms. Can you post this again.

Also explain what the formula is trying to do? Ken Hamady, On-site/Phone Crystal Reports Training/Consulting
Quick Reference Guide to using Crystal in VB
 
The formula's purpose is to extract numeric characters out of a character string that includes '$' and ',' (as well as spaces)

Here's the formula again:

NumberVar i;
stringVar outputcur := "";

**commented out**NumberVar finalcur:=0;

For i:=1 To Length({@Current Year's YTD Calculation}) Do
If Asc({@Current Year's YTD Calculation}) In 48 To 57 Then
outputcur:=outputcur+{@Current Year's YTD Calculation};
**commented out**finalcur:=tonumber(outputcur);

 
You forgot the STEP.
Try this with your field name back in place:

NumberVar i;
stringVar outputcur := "";
NumberVar finalcur:=0;
For i:=1 To Length({@test2})
Step 1
Do
If Asc({@test2}) In 48 To 57 Then outputcur:=outputcur+{@test2};
finalcur:=tonumber(outputcur) Ken Hamady, On-site/Phone Crystal Reports Training/Consulting
Quick Reference Guide to using Crystal in VB
 
What is the significance of STEP / STEP 1? Is it a keyword or function? What does it do for the formula?
 
It tells CR how much to increment the counter on each Loop. If you are going from 1 to 10, and you want to hit every number in between, then you want to step by 1. If you are counting from 10 down to 0, you want to step by -1. I guess you could theoretically step by 3 or 17 or x if you had a reason to. Ken Hamady, On-site/Phone Crystal Reports Training/Consulting
Quick Reference Guide to using Crystal in VB
 
I've added the STEP command to the formula, but it still returns a Boolean value. Below is the current formula. Does this Asc function actually return a whole number as documented or just a Boolean value?

NumberVar i6;
stringVar Coutput6 := "";
NumberVar CurJune:=0;
For i6:=1 To Length({CONTACT2.UFCJUNE})
Step 1
Do
If Asc({CONTACT2.UFCJUNE}[i6]) In 48 To 57 Then
Coutput6:=Coutput6+{CONTACT2.UFCJUNE}[i6];
**commented out//CurJune:=tonumber(Coutput6);
 
It isn't the ASC function, it is that you stopped at the end of the loop logic. If you take off the comments on the last line it should work fine. Ken Hamady, On-site/Phone Crystal Reports Training/Consulting
Quick Reference Guide to using Crystal in VB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top