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

Adding Variables // ltrim??

Status
Not open for further replies.

intel2000

MIS
Jan 22, 2003
25
US
STORE " " TO var0 &&sixdigit long number
STORE " " TO var1 &&sixdigit long number
STORE " " TO var2 &&sixdigit long number
STORE " " To var3 &&sixdigit long number
@6,1 say "ENTER NUMBER:" get var0 function "!" && I enter 444444

read
var1=&var0+1
var2=&var0+2
var3=&var0+3

&&when i do this &var1=" 444445"
&&when i do this &var2=" 444446"
&&when i do this &var3=" 444447"
&& i need var1 to simply be "444445" NOT " 444445"

Why does this add on extra digits? How can I work around this?

 
Not sure of the why. But you are starting with character data types:

STORE " " TO var0

Then they are getting converted to numeric when you execute the statement 'var1=&var0+1', which basically says "evaluate what's contained in the variable 'var0' and add 1 to it, which by default right justfies numeric data, leaving blanks in front.

I order to leave them as character data, left justified, use:

STORE 0 TO var0 &&sixdigit long number
STORE 0 TO var1 &&sixdigit long number
STORE 0 TO var2 &&sixdigit long number
STORE 0 TO var3 &&sixdigit long number
@6,1 say "ENTER NUMBER:" get var0

read

cvar1=ALLTRIM(STR(var0 +1))
cvar2=ALLTRIM(STR(var0 +2))
cvar3=ALLTRIM(STR(var0 +3))
Dave S.
 

Thanks Dave,

This method works but now I've encountered another problem. If I enter a number such as "031225" this chopps off the leading 0. Thats why I used (store " " to var1) ect.
Any Ideas on how to use this new method and have the application not chop off leading 0's. Also when it asks to enter var0 its leaving me room for 10 digits. I need this to allow only 6 digits while not chopping off 0's.

Ive been working with this for the last 2 hours not and havnt been succussful yet........


Thanks,

Ross Lund
 
Ross,
Try:
Code:
var1=transform(var0+1,"@L 999999")
var2=transform(var0+2,"@L 999999")
var3=transform(var0+3,"@L 999999")
The @L adds leading zeros, and the 999999 makes the field six long. You could add a PICTURE clause to limit the number of characters entered. e.g.
Code:
@6,1 say "ENTER NUMBER:" get var0 function "!" picture "######"
Try: "999999" or "NNNNNN" if # doesn't give you what you need.

Rick
 
Well, the problem here is that you're getting into different data types. If you need to enter character data, fine. Numeric, fine. You can't combine the two without converting one of them though. So, if you add numeric 1 to character '01234', you will get an error unless you convert the character '01234'. If you add '1' to it, of course you will end up with '012341'.
In converting character to numeric, you'll lose the '0'. So unless you want all numbers padded with '0's, it will take a lot more fancy programming to remember the original zeros, add numbers, then replace the zeros.

Dave S.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top