Parse an Array Help redux

I am working with arrays and I need a little further assistance on getting a handle on the values. I have some fields whose type is textlist, which means they can have multiple values in each. I need to get a handle on each value individually for use later in the code. Here is what I have thus far:

Field called doi_1 is a text list that has two or more values in every document. Each value is separated by the ‘|’ symbol; for example: 080407|080408.

I need to get a handle on the values ‘080407’ and ‘080408’ individually. Here is a sample of my code, and the results that I get:

for d=0 to ubound(doc.doi_1)

d2 = “hard coded text” + doc.doi_1(d) + “hard coded text”

msgbox d2 (just to actually see the output)

Next

The above code produces:

hard coded text 080407|080408 hard coded text

How do I just grab the first value in the array (080407) and set a temp variable with it, then grab the second value (080408) and do the same? The desired output is:

hard coded text 080407 hard coded text

hard coded text 080408 hard coded text

The other option I tried is:

if doc.doi_1(0) <> “” then forall t in doc.doi_1

d3 = “hard coded text” + t + “hard coded text”

end forall

end if

msgbox t (just to see the output)

The output is the same: hard coded text 080407|080408 hard coded text.

Any help would be greatly appreciated. Thanks.

Subject: Parse an Array Help redux

080407|080408 is not a multiple value. It is a single string value.

All fields in Notes are multi-value when accessed in LotusScript. However, the front end field settings may prevent you from actually entering the values so that they appear as a multi-value in the backend.

If the values were truly in a text list, they would appear in the document properties like this:

“080407”

“080408”

There would be no “|”

This tells me that your values are actually one concatenated string value. The way to break them out is to use the Split function, using the “|” as your delimiter.

Not knowing what you are trying to accomplish, I can’t make more of a suggestion than that.

brandt

Subject: RE: Parse an Array Help redux

Thanks for your reponse Brandt, however I’m still faced with the same issue.

I used the split function to separate the values and used the ubound function to scroll through the entire array to capture all of the values, but I still can’t manipulate each piece of the string. I hope I’m making sense.

What I want to do is separate the concatenated string, and build code around each separated piece of the string. I’m thinking I need to assign temp variables to each piece, but I can’t get a hold on them individually.

Thanks again Brandt, and any other suggestions would be welcome.

Subject: RE: Parse an Array Help redux

What do you mean by “You can’t manipulate each piece of the string?”

I would assume that once you cast the split array into a variant, you would be able to access the different array elements and change them as you see fit.

“Build code” doesn’t do a good job of conveying what you are trying to accomplish. What do you want to do with the strings after you split them?

if we know what you are trying to accomplish, it is easier for us to help.

brandt

Subject: RE: Parse an Array Help redux

I’m creating a text file from each document that the agent runs against. The text file requires opening and closing tags around each value that corresponds to fields in the document.

i.e.

field value

The concatenated strings in the fields in question create this:

field value1|field value2|field value3

What I want is:

field value1

field value2

etc.

The split function does separate the values, however there are several fields that have concatenated strings that need to be accessed to create the output file as follows:

field value1

diff field value1

other field value1

The split function creates this:

field value1

field value2

field value3

diff field value1

diff field value2

diff field value3

other field value1

other field value2

other field value3

Hopefully my explanation is just slightly more clear than mud, and I really appreciate your help.

Subject: RE: Parse an Array Help redux

I am not sure how you are coding it, but I would do something like this:

Dim startDates as Variant

Dim startTimes as Variant

Dim numericField as Variant

Assuming that all of fields you are splitting have strings concatenated with a “|” you would set each variant equal to the split of the desired field. So:

startDates = Split(doc.StartDate(0),“|”)

startTimes = Split(doc.StartTime(0),“|”)

numericField = Split(doc.Numeric(0),“|”)

[this is assuming that your “multi-value” fields are actually just concatenated strings and don’t have actual multiple values. If you have multiple values in a field that are concatenated, you would first have to make sure that each of these fields has an equal number of elements and then create a for loop to access all the values]

Once you have done your splits you can create a new array that you can use to store your tagged data, but you are going to want to verify that the variants containing your split data have equal bounds…otherwise, they will never sync up. But let me warn you from personal experience–THIS IS A BAD WAY TO DO THIS. I guarantee you that something will happen to get the data out of sync. Do not ask me how I know this, just accept that I do, and that it has been a problem for me that will not go away. I would strongly suggest that you redesign the form so that you can create a multi-value field that contains all of the tagged data–something like this:

startDate|startTime|numericValue

The reason I suggest this is that if you concatenate the values like this in a multi-value field and then later use the Strtoken function to explode the value, you don’t need to use split and you won’t need the three variant values above. And you guarantee that the values are in sync. So instead of screwing with three single value fields with concatenated values, you instead deal with one (usually hidden) field that ensures that your data is in sync.

Anyway, once you have managed to determine if the data is in sync, you can do something like this:

Dim taggedData() as String

Redim taggedData(ubound(startDates))

For x = 0 to ubound(taggedData)

taggedData(0) = “” + chr(13) + startDates(x) + chr(13) + “” + chr(13) + “” + chr(13) + startTimes(x) + chr(13) + “” + chr(13) + “” + chr(13) + numericField(x) + chr(13) + “”

Next

Once you do that, each of your taggedData array elements will be equal to the tagging as you desired in the above part of the post.

hth.

brandt

Subject: RE: Parse an Array Help redux

Brandt,

First off let me thank you again for your time and diligence in helping with this matter. I agree totally that redesigning the form is the best practice, however I am in a situation where I inherited a legacy application and I have to manipulate the data therein. I don’t have the option of changing the form design or re-training the user community that uses the application. (If only it were so simple.)

The suggestion that you made works like a charm, however there is one last piece that puzzles me. I can format the data and get all of the values that I desire, and I even put in a msgbox taggeddata(0) between the ‘for x = 0 to ubound’ and the ‘Next’ statement to see the desired output. However, if I move the msgbox taggeddata(0) out of the For - Next loop, it only displays the last element in the array. I want to grab the taggeddata(0) string in its entirety and plug it into the Print line of the output file to get the end result. How do I do that so that the total array values are displayed?

Once again thanks for all of your help.

Subject: RE: Parse an Array Help redux

So I am assuming what you are saying is that you want to take all of the elements of the array and concatenate it into one giant string? Then you would do something like this:

Dim tagString as String

For x = 0 to Ubound(taggedData)

If x = 0 then

tagString = taggedData(0)

Else

tagString = tagString + chr(13) + taggedData(x)

End If

then print tagString

From your original post, I assumed you wanted the different tagged sections individualized, or that you were going to dump the contents into a multi-value text field.

brandt

Subject: RE: Parse an Array Help redux

Brandt,

Sorry I wasn’t more clear in my original post.

With both of the latest code suggestions that you provided, when I add the print statement, it only prints the last element in the array. There is a document in the Db that I have been testing with, and it has a total of 12 elements in an array. When I run the print statement or a msgbox within the loop, it displays all elements of the array (0-11). As soon as I move the print statement or msgbox outside of the loop (after the ‘Next’ statement) it only produces the last element in the array.

I thought that setting a temp variable (string) to the value of the array would produce the desired result, but I am mistaken. Any last suggestions?

Thanks again.