Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Array Dimensions - Confusing VFP
Message
De
09/08/2002 07:09:15
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Problèmes
Divers
Thread ID:
00687552
Message ID:
00687878
Vues:
14
>Hello!
>
>I have a Problem Programming a variable Array handling Program.
>Here is the Problem:
>
>Dimension a(2)
>a(1)="Hello"
>a(2)="I am Marvin"
>
>?a(1,1) -> Delivers "Hello"
>?a(2,1) -> Delivers "Hello" ... this really brings me to confusion
>
>?alen(a,1) -> delivers 1 ...WHY??? Why not 2
>
>So I work around my Problem with alen(a,2).
>Now I decide to let my Array be 2 Dimensional. Great so long...
>
>Dimension a(2,3)
>a(1,1)="Hello"
>a(1,2)="C"
>a(1,3)=1
>
>a(2,1)="I am Marvin"
>a(2,2)="A"
>a(2,3)=2
>
>?alen(a,2) -> delivers 3 ... which is not the Value I'd like to work with.
>So I use the :
>?alen(a,1) -> delivers 2 ... juhu
>
>This lets me decide to use the Multi Dimensional Array like this
>Dimension a(2,3)
>a(1,1)="Hello"
>a(2,1)="C"
>a(3,1)=1
>
>a(1,2)="I am Marvin"
>a(2,2)="A"
>a(3,2)=2
>
>But.. how do I delete a complete element...
>ok with adel(a,2,2)
>Now I'd like to have a look with the Debugger... no chance to get the correct Display.
>
>Why does the Afields(a) command show me the incorrect way?
>Many questions, but no solution. All I know is that this behaviour is more than confusing to me.
>Just wanted to let out my confusion.... *ggg*

Marvin,
You're right to be confused.

dimension arrTest[2]
arrTest[1] = "Hello Marvin"
arrTest[2] = "I'm Cetin:)"

? arrTest[1,1]
? arrTest[2,1]
? arrTest[1000,1]

All would return 1st element !!!
So first you should reason here in one dimensional arrays first subscript is ignored. Yes and no. It's ignored as long as the first value is less than or equal to array limit (65000 now). As you passed that VFP errors :)

More fun :
dimension arrTest[3,2]
FOR ix=1 TO 3
  FOR jx=1 TO 2
    arrTest[ix,jx] = trans(ix)+'_'+trans(jx)
  ENDFOR
endfor
? arrTest[2,2] && 2_2
? arrTest[2,3] && 3_1

So my personal reasoning how VFP calculates :
nRow*Columns+nCol
Using 0 for one dimensional arrays and checking gte 65000 internally before trying to return a value.

And yet more fun :
CREATE CURSOR myCursor (f1 i,f2 i)
dimension arrTest[1000]
FOR ix=1 TO 1000
  arrTest[ix] = ix
ENDFOR
APPEND FROM ARRAY arrTest
What do you expect to see :) Only one record with 1,2 ? yes guessed right:) Go on :
dimension arrTest[1000,1] && Promote to 2 dimensional array
APPEND FROM ARRAY arrTest
browse 
dimension arrTest[1000,2] && Promote to 2 columns array
APPEND FROM ARRAY arrTest
browse 
Not very confusing indeed and honestly sometimes I use these for tricky transpositions :)
ains() and adel() are similarly confusing. BTW a simple array displayer you might want to use during tests (I find easier than disp memo or debugger in cases):
function DisplayArray
lparameters taArray && pass by ref
lnOldSize = _screen.fontsize
lcOldFont = _screen.fontname
_screen.fontname = "Courier New"
_screen.fontsize = 8

?
local array arrColSize[alen(taArray,2)]
for ix = 1 to alen(taArray,2)
	lnColSize=0
	for jx = 1 to alen(taArray,1)
		lnColSize = max(len(trans(taArray[jx,ix])),lnColSize)
	endfor
	arrColSize[ix]=lnColSize
endfor

for ix = 1 to alen(taArray,1)
	for jx = 1 to alen(taArray,2)
		?? ' '+padr(trans(taArray[ix,jx]),arrColSize[jx])+" |"
	endfor
	?
	for jx = 1 to alen(taArray,2)
		?? replicate("-",arrColSize[jx]+2)+"+"
	endfor
	?
endfor
?
_screen.fontname = lcOldFont
_screen.fontsize = lnOldSize
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
Répondre
Fil
Voir

Click here to load this message in the networking platform