Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
List elements of a field in an array
Message
 
To
20/04/2004 12:35:06
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00896552
Message ID:
00896605
Views:
12
>How can I get each element in a field in to an array?
>
>The field schres has data such as SDE,EPY,CMA
>
>My select statement:
>Select schres From schtbld Where schwk = CTOD("04/18/04") And !Empty(schres) InTo Array sch_man_power
>
>yeilds the entire string as first element of array. I need SDE as first element, EPY as second element, and so on.
>
>Thanks for help

Just exercising the alternatives :)
Assuming that there may be multiple records in the result set, any number of codes in the field, but all the codes have three characters:
DIMENSION laValues[1]
lcfields = ""

* calculate the highest number of codes in the field
SELECT MAX(GETWORDCOUNT(schres, ",")) FROM schtbld INTO ARRAY acount1

* build the fields string for SELECT statement
FOR N = 1 TO acount1[1]
	lcfields = lcfields + " PADR(GETWORDNUM(field1," + TRANSFORM(N) + ", ','), 3,' ')" +;
        IIF(N < acount1[1], ',','')
ENDFOR

SELECT &lcfields FROM schtbld WHERE... INTO ARRAY laValues
However, you should deal with possible empty elements.
Nick Neklioudov
Universal Thread Consultant
3 times Microsoft MVP - Visual FoxPro

"I have not failed. I've just found 10,000 ways that don't work." - Thomas Edison
Previous
Reply
Map
View

Click here to load this message in the networking platform