Think of something that you wish Authorware could do but it doesn't?  Let the our good friends at Macromedia know via the wishlist.

Please let us know if you find any of the materials on this site inappropriate or offensive. Please include the url and why the material should be reviewed.

Comments and questions about the site are also welcome. Please no Authorware questions, use the AWARE list.

Back

B7011 - Why do funny things happen when I append a string to a list?

by - Joseph Ganci


Mr. Ganci (Obi-Wan of multimedia),

I came across an interesting dilemma when trying to concatenate string and list variables for writing out as data to a text document.

I'm return-delimiting string information using:

DATA_String := StudentName^Return
DATA_String := DATA_String^StudentNumber

Which results in DATA_String containing two lines of text for the WriteExtFile (StudentName and StudentNumber are strings). However, if I add a List Variable to the structure, as:

DATA_String := StudentName^Return
DATA_String := DATA_String^StudentNumber^Return
DATA_String := DATA_String^Test_List -- Test_List is a List Variable; like Test_List[15,24,33,42,51]
the StudentName and StudentNumber get placed into each element of the Test_List. The result in DATA_Sring is:

["Sam Smith
1234
15","Sam Smith
1234
24","Sam Smith
1234
33","Sam Smith
1234
42","Sam Smith
1234
51"]

I was expecting the text file to have:

Sam Smith
1234
[15,24,33,42,51]

I can get the List Variable (Test_List) written out by itself using:

DATA_String := CopyList(Test_List)

which results in the text file having [15,24,33,42,51].

I've attached a sample of source code with examples of each script for you to test (WriteExtFile is disabled).

The only "work around" I've come up with is to extract each element from the List Variable using a repeat loop and tab-delimiting the results into a "temp" variable. Then writing out the results (see attached example - Work Around button). I can't find any information regarding a proper technique for exporting List Variable values to external data files.

Thanks for taking the time to give this a look...


Long question, short answer. Funny things happen when you try to concatenate a list to a string. The string contents get appeneded to every location in the list. The solution is to use the String function, to convert the list to a string first. Then you'll be fine. So you want for your last line:

DATA_String := DATA_String^String(Test_List)

There are 0 reviews
Add your review
Back