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

Array/subscript error 2

Status
Not open for further replies.

LindaC

Programmer
Oct 18, 1999
97
US
Hi All,<br>&nbsp;&nbsp;&nbsp;I am using CR8.&nbsp;&nbsp;My problem is I need to take a character field (NAME) and break it apart to get last name and first initial.&nbsp;&nbsp;I cannot use LEFT (string,# of places) as I don't know how many places.&nbsp;&nbsp;The field looks like this:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Castner, Linda<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Ciani, Susan<br><br>I have tried to tell CR that the name field is an array and read each character till I reach a ','.<br><br>stringVar array lastname := [{GENERAL_PROFILE.INDIV_NAME}];<br>numberVar x := 1;<br>while lastname [x] &lt;&gt; ',' do <br>&nbsp;&nbsp;(if x &gt; 23 then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit while; <br>&nbsp;&nbsp;&nbsp;x := x + 1);<br>Left ({GENERAL_PROFILE.INDIV_NAME}, x);&nbsp;&nbsp;<br><br>When I check the formula I get no errors, but, when I run the report I get the error:<br><br>&nbsp;&nbsp;A subscript must be between 1 and the size of the array. <br><br>The field is 24 characters long.&nbsp;&nbsp;Could someone point me in the right direction please? <p>LindaC<br><a href=mailto:lcastner@co.orange.ny.us>lcastner@co.orange.ny.us</a><br><a href= > </a><br>
 
The following should work:<br><br>NumberVar Comma;<br>Comma:= InStr ({GENERAL_PROFILE.INDIV_NAME},',');<br>if comma &gt; 1 then<br>&nbsp;&nbsp;&nbsp;&nbsp;if Length({GENERAL_PROFILE.INDIV_NAME}) &gt; comma + 2 then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mid({GENERAL_PROFILE.INDIV_NAME}, Comma + 2,1)&nbsp;&nbsp;+ &quot;. &quot;&nbsp;&nbsp;+ Left ({GENERAL_PROFILE.INDIV_NAME},comma -1);<br><br>Let me know if it works for you. Thanks.
 
I would use string searches rather than arrays, probably cause I feel more comfortable with them:<br>NumberVar CommaPosition := 0;<br>StringVar LastName := '';<br>StringVar FirstInit := '' ;<br>CommaPosition := InStr({GENERAL_PROFILE.INDIV_NAME}, ',') ;<br>LastName := {GENERAL_PROFILE.INDIV_NAME} [1 to CommaPosition - 1] ;<br>FirstInit := {GENERAL_PROFILE.INDIV_NAME} [CommaPosition + 2]<br> <p>Malcolm Wynden<br><a href=mailto:wynden@island.dot.net>wynden@island.dot.net</a><br><a href= > </a><br>
 
THANK YOU BOTH!!!!&nbsp;&nbsp;Yes, they both work.&nbsp;&nbsp;I just need to break it into 2 formulas as this will be a file sent to a state office.&nbsp;&nbsp;Thank you both again. <p>LindaC<br><a href=mailto:lcastner@co.orange.ny.us>lcastner@co.orange.ny.us</a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top