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!

ARRAYS - sorry newbie

Status
Not open for further replies.

psvialli

Technical User
Apr 8, 2004
29
GB
newbie question !

I have an array and I need to copy the array to a memo field but i only get the first line of the array, can somone please let me know where i am going wrong. Thanks

use claims
DIMENSION aMyArray(4)
COPY TO ARRAY aMyArray FIELDS
address1,address2,address3,address4
GATHER FROM aMyArray FIELDS address MEMO
 
I think there is no function to collect strings from all array elements into a single string. Maybe one reason for it is, that in FoxPro not all array elements must be of same type.

So if you have strings in all elemenents, you can program it:

LOCAL lcFull
lcFull = ''
FOR lni=1 TO ALEN( aMyArray, 1 )
FOR lnj=1 TO ALEN( aMyArray, 2 )
lcFull = m.lcFull + ' - ' + aMyArray[m.lni, m.lnj]
ENDFOR
lcFull = m.lcFull + CHR(13)+CHR(10)
ENDFOR
REPLACE NEXT 1 Address WITH m.lcFull
 
Gather will only gather one line of the array. Make it that way:

Code:
#define CRLF chr(13)+chr(10)
LOCAL lcAdress
lcAdress = adress1+CRLF+adress2+CRLF+adress3+CRLF+adress4
Replace address with lcAdress

and if you want to stay with the array idea, here's code for glueing together lines of an array:

Code:
#define CRLF chr(13)+chr(10)
Local lcText
lcText = ""
For each lcLine in laMyArray
   lcText = lcText + lcLine + CRLF 
endfor

and tehn replace with lcText...

Bye, Olaf.
 
Pscvialli,

Just to expand on Olaf's code:
Code:
#define CRLF chr(13)+chr(10)
Local lcText
lcText = ""
For each l[b]u[/b]Line in laMyArray
   lcText = lcText + [b]TRANSFORM(luLine)[/b] + CRLF 
endfor
That way, it will work regardless of the data type(s) used in the array.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
I know this is not really relevant, but I have just been developing a report using Crystal Report's formula language. They have a very handy function called JOIN(), which does just what Psvalli wants, in one line of code:

lcSomeString := JOIN(laMyArray)

And you can add a second argument to specify a delimiter.

That would be a nice addition to VFP.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
psvialli,

>>I have an array and I need to copy the array to a memo field but i only get the first line of the array, can somone please let me know where i am going wrong.<<

I'm not quite sure what you are trying to acomplish here. If you want to save the array as an array and later restore it to an array, see the SAVE TO and RESTORE FROM commands in the VFP help file. I would not recommend this technique for data storage but I have used it for logging purposes, where I wanted to be able to debug failed inserts or updates to a SQL database after the fact.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top