Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Transforming an ARRAY
Message
De
05/11/1998 11:55:47
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00153394
Message ID:
00154866
Vues:
22
Scott,
My 2 cents about this subject. Being frankly, I don't know anything about ADOset and its commands so I might be saying that worth nothing :)
I can understand you need the first array but if the second one will also be an array, why transform it ? You could refer the new pos as X*Y. Or why not do a simple conversion w/o cursor ?
dimension myarray[X,Y]
for ix=1 to alen(myarray,1)
	for jx=1 to alen(myarray,2)
	    myarray[ix,jx] = padl(ix,50,"0")+"-"+padl(jx,50,"0")
	endfor
endfor
dimension myarray1[Y,X]
for ix=1 to alen(myarray1,1)
	for jx=1 to alen(myarray1,2)
	    myarray1[ix,jx] = myarray[jx,ix] 
	endfor
endfor
OTOH you could directly get it to "transformed array" w/o intermediate one. But I wonder such a populated array would work seamlessly with a listbox control. Instead I would prefer creating a "transformation" cursor and populate it from ADOset, then set RowSourceType to fields.
Cetin

>Jim,
>
>Your not going to believe what this other fellow came up with but it does work. Here's my reply to him on another list, and my revised code of his suggestion.
>---------------------------------------------------------
>Frank,
>
>You win! This works. Here is the test routine:
>
>DIMENSION laTest[2,5]
>laTest[1,1] = "Scott"
>laTest[1,2] = "Kirsten"
>laTest[1,3] = "Peter"
>laTest[1,4] = "Andy"
>laTest[1,5] = "Ralph"
>laTest[2,1] = "Hurlbert"
>laTest[2,2] = "Schultz"
>laTest[2,3] = "McKay"
>laTest[2,4] = "Hall"
>laTest[2,5] = "Samuels"
>*
>clear
>display memo like laTest
>LOCAL lnRows, lcCol, lnCols
>create cursor cur (col1 c(20), col2 c(20), col3 c(20), col4 c(20), col5 c(20)) && one column for each array
>append from array laTest && copy array into cursor
>lnRows = reccount("cur")
>lnCols = alen(laTest, 2)
>declare aTargetArray(lnCols, lnRows)
>for i = 1 to lnCols
> lcCol = alltrim(str(i))
> select col&lcCol from cur into array aTempArray && one select for each column
> =acopy(aTempArray,aTargetArray,1,lnRows,i*lnRows-lnRows+1)
>endfor
>display memo like aTargetArray
>
>This does what I need. It's takes the output of an ADO recordset's "getrows" method and turns it into something a listbox or combo can use.
>
>Now, this method was faster by about 20% on a recordset with 2800 rows. I suspect the gains would be more for higher numbers of rows and probably less for smaller. The old array rearrange would probably be faster for recordsets of less than 1000 rows; 1000 is my guess for the breakeven between the two methods.
>
>Of course, for smaller methods it doesn't matter because both routines are "fast enough."
>
>One note, things get complicated if you start dealing with lots of data types. This works real well for a list of strings but start throwing in integers and dates and building the cursor is going to be a pain in the butt.
>
>Thanks, Scott
>
>
>>>Jim,
>>>
>>>You're right about the size of the array. My current recordset is 3,000 records, so 65,000 won't be a problem.
>>>
>>>ACOPY() won't rearrange the array. The array is WIDE by TALL and I need it TALL by WIDE.
>>
>>Scott,
>>
>>In that case your code is about the only way you can get it done. Inverting matrix takes time.
>>
>>You might do better to leave it alone and process it the way it is.
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform