Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Adding a column to an array
Message
De
30/12/2003 10:58:23
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
30/12/2003 10:43:58
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00862826
Message ID:
00862841
Vues:
19
This message has been marked as the solution to the initial question of the thread.
>If I have an array like so:
>
>myarray(1,1)= "Item 1"
>myarray(1,2)= "Apples"
>myarray(2,1)= "Item 2"
>myarray(2,2)= "Oranges"
>
>and I want to add a 3rd column to the array so I will end up with the following:
>
>myarray(1,1)= "Item 1"
>myarray(1,2)= "Apples"
>myarray(1,3)= .F.
>myarray(2,1)= "Item 2"
>myarray(2,2)= "Oranges"
>myarray(2,3)= .F.
>
>How do I do it? When I redimension myarray(2,3) it looks like this:
>
>myarray(1,1)= "Item 1"
>myarray(1,2)= "Apples"
>myarray(1,3)= "Item 2"
>myarray(2,1)= "Oranges"
>myarray(2,2)= .F.
>myarray(2,3)= .F.
>
>The AINS() seems to do the same thing...
>
>TIA!
local array myArray[2,2]
myarray(1,1)= "Item 1"
myarray(1,2)= "Apples"
myarray(2,1)= "Item 2"
myarray(2,2)= "Oranges"
InsDelColumn(@myArray,2,2)
Display Memory like myArray

* function InsDelColumn
* Insert or remove a column from array at the end column
* Resize array to lnRows, tnCols if remove, lnRows, tnCols+1 if add
FUNCTION InsDelColumn
LPARAMETERS taTempArray, tnRows, tnCols, tlRemove
LOCAL ix

* Conv. to one dim - just for ease of coding array subscript
DIMENSION taTempArray[tnRows * (tnCols + 1)]

FOR ix = iif(tlRemove,tnRows,1) to iif(tlRemove,1,tnRows) step iif(tlRemove,-1,1)
	IF tlRemove && Is it a column removal ?
		=adel(taTempArray,(ix-1) * (tnCols + 1) + (tnCols + 1))
	ELSE       && or column add ?
		=ains(taTempArray,(ix-1) * (tnCols + 1) + (tnCols + 1))
	ENDIF
ENDFOR

&& Back to two dim. with resize
DIMENSION taTempArray[tnRows,( tnCols + iif(tlRemove,0,1) )]
Cetin
Ç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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform