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!

How to add strings together 1

Status
Not open for further replies.

baggetta

Technical User
Feb 27, 2003
116
US
How do I add string variables together so I can store it into a new variable?

Example:
define var x-date as date.
define var x-edicont as char format "x(8)".
define var x-cont as char format "x(19)".
define var x-holder as char.
x-holder = "@".
x-date = today.
x-edicont = "00976736"

x-cont = x-edicont + x-holder + x-edicont.

Result x-cont = "00976736@11/10/03"
 
Um, I think in your example you meant

x-cont = x-edicont + x-holder + x-date.

You're very close. String the date:

x-cont = x-edicont + x-holder + string(x-date).

If you want the date to have a specific format, you can do:

x-cont = x-edicont + x-holder + string(x-date,"99/99/9999").

fyi, the default is "99/99/99".
Then when you are done, just do:

disp x-cont format "x(30)"

to make sure it worked like you wanted.

Also, you should use ASSIGN for multiple assignments - it reduces .r code size and helps speed things up just a tad. You honestly won't see any difference unless you had a HUGE amount of single assignments, but it's good practice to always use ASSIGN:

assign x-holder = "@"
x-date = today
x-edicont = "00976736"
x-cont = x-edicont + x-holder + x-edicont.

Hope that helps!

Rich
 
Another way is:-

def var x-date as date.
def var x-edicont as char format "x(8)".
def var x-cont as char format "x(19)".

assign
x-date = today
x-edicont = "00976736"
x-cont = x-edicont + "@" + string(x-date).

message "x-cont is: " + x-cont.

Chris

It worked yesterday.
It doesn't work today.
That's Windows!
 
FYI, you don't need the + in the message statement in this example. You can just do

message "x-cont is: " x-cont.


Just trying to be helpful, not rude. :)

Rich

 
Thanks Rich,

I don't usually put a + in the message statement, just an aberation.

Chris

Chris

It worked yesterday.
It doesn't work today.
That's Windows!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top