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

Join 2 arrays to form 1 string 1

Status
Not open for further replies.
Oct 23, 2007
24
US
2 fields (can be one or more value each delimited with an '&' sign):

- Service Code (string)
ie. 100&200&CH&400&TV
- Service Description (string)
ie. Laundry&Plumbing&Cable and Heat&Wireless&Television

Known facts:
1) # of Service Description = # of Service Codes
2) 1st Service Description matches 1st Service Code, 2nd Service Description matches 2nd Service Code, etc.

I would like to combine these 2 strings to create one single string that would display like:

(100) Laundry
(200) Plumbing
(CH) Cable and Heat
(400) Wireless
(TV) Television

My code:
==========================================================
whileprintingrecords;
StringVar Array ServiceCodeVar;
StringVar Array ServiceDescVar;
StringVar Service;
NumberVar Counter;

ServiceCodeVar := Split({table.service_codes}, "&");
UBound(ServiceCodeVar);


ServiceDescVar := Split({table.service_desc}, "&");
UBound(ServiceDescVar);


For Counter:= 1 to UBound(ServiceCodeVar) do
(
Service:= "(" + ServiceCodeVar[Counter] + ") " + ServiceDescVar[Counter] + chr(10);
);

Service;

===========================================================

Unfortunately this formula I wrote did not seem to loop through all the elements, it only shows the last element on the report:
(TV) Television

Any help will be appreciated. Thanks!
 
Give this a try:

local stringvar input_svc_codes := "100&200&CH&400&TV";
local stringvar input_svc_descs := "Laundry&Plumbing&Cable and Heat&Wireless&Television";

local stringvar array arr_codes := split(input_svc_codes,"&");
local stringvar array arr_descs := split(input_svc_descs,"&");

local numbervar x;
local stringvar output := "";

for x := 1 to ubound(arr_codes)
do
(
output := output & chr(13) & "(" & arr_codes[x] & ") " & arr_descs[x]
);

mid(output,2)

Substitute your fields for the hard coded strings at the beginning.

~Brian
 
Also, make sure you set the Can Grow property on the field after you place it on the report so that it shows all potential values.

~Brian
 
Thanks a lot Brian! It's working now!

PS: yeh I did have the Can Grow on but even so, my old formula was not working the way I wanted it to.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top