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

subtracting variables - a rookie question

Status
Not open for further replies.

lvadmin

MIS
May 5, 2004
28
US


eventtimenew = eventtime - newtime
@1,1 say eventtimenew


I get 100020(should really be 9980.)
1000 - 20

eventtimenew = "eventtime" - "newtime"

I get eventtimenewtime


What am I doing wrong here?
 
Lvadmin,

It looks like you are substracting two strings. When you do that. VFP joins the strings together, while removing any intermediate spaces.

Try this:

eventtimenew = val(eventtime) - val(newtime)
@1,1 say eventtimenew

That will convert the strings to numbers. Subtraction will then work as you expect it to.

Mike



Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Nice

The calculation works nice but I want to sent that to another variable and get rid of the decimal in 9980.00

I am having a problem saying:

store substr(eventtimenew,1,4) to test
say test

I get an error????

help
 
Code:
store str(eventtimenew,1,4) to test
say test

Regards,

Mike
 
Lvadmin,

I am having a problem saying:
store substr(eventtimenew,1,4) to test


That's because EventTimeNew is a numeric variable, and substr() only works on strings. Use the STR() function to convert numeric to string. The third argument of that function specifies how many decimal places you want.

Mike



Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top