-
-
Notifications
You must be signed in to change notification settings - Fork 45
Closed
Labels
Description
it seems it's not possible to create a two dim array if the number of columns is 1
These are the Foxpro results.
dimension arr1(1,1), arr2(3,1), arr3(1,3)
ARR1 Priv A
( 1, 1) L .F.
Alen(arr1,0) = 1 Alen(arr1,1) = 1 Alen(arr1,2) = 1
ARR2 Priv A
( 1, 1) L .F.
( 2, 1) L .F.
( 3, 1) L .F.
Alen(arr2,0) = 3 Alen(arr2,1) = 3 Alen(arr2,2) = 1
ARR3 Priv A
( 1, 1) L .F.
( 1, 2) L .F.
( 1, 3) L .F.
Alen(arr3,0) = 3 Alen(arr3,1) = 1 Alen(arr3,2) = 3
And the X# code
DIMENSION arr1(1,1), arr2(3,1), arr3(1,3)
?
ShowFoxArray (arr1)
? "Alen(arr1,0) = " + AllTrim(Str(ALen(arr1,0))) + " ", "Alen(arr1,1) = " + AllTrim(Str(ALen(arr1,1))) + " ", "Alen(arr1,2) = " + AllTrim(Str( ALen(arr1,2)))
?
ShowFoxArray (arr2)
? "Alen(arr2,0) = " + AllTrim(Str(ALen(arr2,0))) + " ", "Alen(arr2,1) = " + AllTrim(Str(ALen(arr2,1))) + " ", "Alen(arr2,2) = " + AllTrim(Str( ALen(arr2,2)))
?
ShowFoxArray (arr3)
? "Alen(arr3,0) = " + AllTrim(Str(ALen(arr3,0))) + " " , "Alen(arr3,1) = " + AllTrim(Str(ALen(arr3,1))) + " " , "Alen(arr3,2) = " + AllTrim(Str( ALen(arr3,2)))
?
results in
a[1] = .F. (Nil)
Alen(arr1,0) = 1 Alen(arr1,1) = 1 Alen(arr1,2) = 0
a[1] = .F. (Nil)
a[2] = .F. (Nil)
a[3] = .F. (Nil)
Alen(arr2,0) = 3 Alen(arr2,1) = 3 Alen(arr2,2) = 0
a[1] [1,1] = .F. (Nil)
a[2] [1,2] = .F. (Nil)
a[3] [1,3] = .F. (Nil)
Alen(arr3,0) = 3 Alen(arr3,1) = 1 Alen(arr3,2) = 3
Because i want a different Fox-Array view than the ShowArray() function offers, i created the ShowFoxArray() function. And since its now possible, i also took the chance and added a LOCAL FUNCTION to the ShowFoxArray () :-)
FUNCTION ShowFoxArray ( aTest AS __FoxArray , cPrefix := "" AS STRING ) AS VOID
LOCAL i, j, dwCounter AS DWORD
// todo: If AElement() works as expected, remove the dwCounter var
IF cPrefix:Length == 0
cPrefix := "a"
ENDIF
IF aTest:MultiDimensional
dwCounter := 0
FOR i := 1 TO ALen ( aTest , 1 )
FOR j := 1 TO ALen ( aTest , 2 )
dwCounter ++
? cPrefix + "[" + dwCounter:ToString() + "] [" + i:ToString() + "," + j:ToString() + "] = " + AsString ( aTest [i,j] ) + ;
" " + GetElementValueType ( aTest[i,j] )
// todo: If AElement() works as expected, remove the code above and use the code below instead:
//
// ? cPrefix + "[" + AElement ( aTest , i , j ):ToString() + "] [" + i:ToString() + "," + j:ToString() + "] = " + AsString ( aTest [i,j] ) + ;
// " " + GetElementValueType ( aTest[i,j] )
NEXT
NEXT
ELSE
FOR i := 1 TO ALen ( aTest , 0 )
? cPrefix + "[" + i:ToString() + "] = " + AsString ( aTest [i] ) + " " + ;
GetElementValueType ( aTest[i] )
NEXT
ENDIF
LOCAL FUNCTION GetElementValueType( uValue AS USUAL ) AS STRING
IF IsNil ( uValue )
RETURN "(Nil)"
ELSE
RETURN "(" + ValType ( uValue ) + ")"
ENDIF
END FUNCTION
RETURN
END FUNCTION
Karl-Heinz