|
Hi.
Is it possible to dynamically assign values to specific array subscripts? I'm trying to do something like this:
CRCount := CRCount + 1; CRPos[CRCount] := TmpCRPos; TmpCRPos := InStr(TmpCRPos, SString, Chr(13))
Where CRPos is a numberVar array, CRCount increases in a loop with no defined limit, and TmpCRPos is the value I'm loading to a subscript on each loop iteration.
Basically, I don't know what the values are, nor how many I will have, until the very end of a long nested loop. Every time I try to assign a value to a specific subscript, I get this error:
A subscript must be between 1 and the size of the array.
It sounds like I need to define the number of subscripts in my array before I start populating them with values, but I'm not even sure of that.
I'm using CR 8.5, by the way, so I may not have access to all the functions and operators newer versions might have.
Thanks.
EDIT Hmm. I just discovered REDIM PRESERVE. That sounds like what I was looking for.
Edited by Dreaming - 26 Feb 2010 at 10:02am
|
|
OK, so I've been going in circles with this for a while now and I just can't seem to get it to behave. What's suppose to happen is that four separate strings consisting of 250 characters each are pulled from the same memo field (this is to split the field up into strings that can be worked with).
Next, going one field at a time, each is supposed to be checked for occurrences of carriage returns (Chr(13)), and report back with the location of each. Those locations should then be stored in an array to be called on later in the formula. The kicker is that the positions must be contiguous, as they are found in the memo. This is why, depending on which string is being actively worked on, the position returned with InStr() has either 0, 250, 500, or 750 added to it before it is placed into the array.
The last thing to note is that after the first string (always {%Pull_1}), the remainder of pulls may or may not be NULL. If one is encountered as NULL, the FOR loop should exit immediately as the array should then be complete.
So after chasing my tail hammering down infinite loop errors, I don't seem to be able to get past this one where the reports stops on a An array's dimension must be an integer between 1 and 1000 error. I've tried reconfiguring this piece of code in a dozen ways to alleviate this, until ending up with this verbose section -- which still fails.
My impression is that for some reason, TmpCRPos never evaluates as 0, therefore never leaves the WHILE loop and keeps passing new variables to the array infinitely. I just can't see why. It may be something I don't understand about how InStr() functions since this plays a major role in controlling the logical flow.
So here's the code segment if anyone wants to take a look at it. Again, any insights would be appreciated.
FOR X := 1 TO 4 DO ( IF X = 1 THEN ( IF ISNULL({%Pull_1}) THEN EXIT FOR ELSE ( SString := {%Pull_1}; FALSE ) ) ELSE IF X = 2 THEN ( IF ISNULL({%Pull_2}) THEN EXIT FOR ELSE ( SString := {%Pull_2}; FALSE ) ) ELSE IF X = 3 THEN ( IF ISNULL({%Pull_3}) THEN EXIT FOR ELSE ( SString := {%Pull_3}; FALSE ) ) ELSE ( IF ISNULL({%Pull_4}) THEN EXIT FOR ELSE ( SString := {%Pull_4}; FALSE ) );
TmpCRPos := InStr(SString, Chr(13)); //Initializes TmpCRPos with position of first carriage return of current pulled string WHILE TmpCRPos <> 0 DO ( IF X = 1 THEN ( CRCount := CRCount + 1; IF CRCount = 1 THEN ( REDIM CRPos [CRCount]; 0 ) ELSE ( REDIM PRESERVE CRPos [CRCount]; 0 ); CRPos[CRCount] := TmpCRPos; TmpCRPos := InStr(TmpCRPos, SString, Chr(13)); ) ELSE IF X = 2 THEN ( CRCount := CRCount + 1; IF CRCount = 1 THEN ( REDIM CRPos [CRCount]; 0 ) ELSE ( REDIM PRESERVE CRPos [CRCount]; 0 ); CRPos[CRCount] := TmpCRPos + 250; TmpCRPos := InStr(TmpCRPos, SString, Chr(13)); ) ELSE IF X = 3 THEN ( CRCount := CRCount + 1; IF CRCount = 1 THEN ( REDIM CRPos [CRCount]; 0 ) ELSE ( REDIM PRESERVE CRPos [CRCount]; 0 ); CRPos[CRCount] := TmpCRPos + 500; TmpCRPos := InStr(TmpCRPos, SString, Chr(13)); ) ELSE IF X = 4 THEN ( CRCount := CRCount + 1; IF CRCount = 1 THEN ( REDIM CRPos [CRCount]; 0 ) ELSE ( REDIM PRESERVE CRPos [CRCount]; 0 ); CRPos[CRCount] := TmpCRPos + 750; TmpCRPos := InStr(TmpCRPos, SString, Chr(13)); ) ELSE 0; ); // End WHILE loop ); // End FOR loop
And just a quick note about the source data. I've confirmed there are three carriage returns in the first pulled string I use, none in the second although the string is not NULL, with the final third and fourth pulled strings being entirely NULL.
|