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!

Val()

Status
Not open for further replies.

SharonBrown

Technical User
Mar 2, 2001
3
US
I wrote a message earlier (see below) and I had a great answer by Ken, but I cannot find any information on Val().
Does anyone know where I can read up on this or can you give me an example? Thanks!

I need to change two data fields that were created as "varchar" by our programmer. The two fields display the hours worked per day and the number of days per week. He needed to display the answer in our application. I need to be able to use the information to place in a report.

How can you change this to a number so I can sum the two together?

Thanks,
Sharon



 
SharonBrown: You would be well advised to try a formula like the following:

if NumericText(field1) then ToNumber(field1) else Val(field1)

The NumericText() function first checks your field for the presence of any alpha (or more precisely non-numeric) characters and if it passes then the ToNumber() function will return the numeric value.

The Val() function will also return a numeric value but will stop converting at the first non-numeric character e.g. if your field is "8.00" then ToNumber() will give you 8 but if it is "8.00 hrs" then ToNumber() will throw an error whereas Val() will give you 8

HTH David C. Monks
david.monks@chase-international.com
Accredited Seagate Enterprise Partner
 
What version of CR?

If you go into the help index of any recent version, you should find VAL described. If it isn't there, you might not have the function in your version. ToNumber is the older equivalent, however, as DCM pointed out, ToNumber can't deal with any characters, while VAL can deal with characters if they are after the numbers. Ken Hamady
Crystal Reports Training/Consulting and a
Quick Reference Guide to VB/Crystal (including ADO)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top