Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array problem in Foxpro

Status
Not open for further replies.

takyan

Programmer
Oct 16, 2002
84
HK
Hi all,

Is it possible create 3-dimension or multi-dimension array in forpro??
Please advise.

Yan
 
Takyan,

If you are talking about an array like aryVar(3,6,4) then I would say NO. But I haven't ever found somewhere that I needed an array like that either. As to a multidimensional array such as aryVar(3,2) then YES. As JustDo said:

Dimension aryVar(3,2)
or
Declare aryVar(3,2)
or
Public Array aryVar(3,2)
or
Local Array aryVar(3,2)

Slighthaze = NULL
 
Taykan

This is a way to create a multidimensional array:
Code:
CreateArray("HellDim", 3, 6, 3, 8, 2)
for x=1 to 6
    for y = 3 to 8
        PutArray( x*y, "HellDim", 3, x, 1, y, 1)
    next y
next x

? GetArray("HellDim", 3, 6, 1, 8, 1)
func CreateArray
 parameters par1, par2, par3, par4, par5, par6, par7, par8, par9
 local paramt, counter, arrayname, dims, paramvalue
 local dim1, dim2, dim3, dim4, dim5, dim6, dim7, dim8, fillarray

 paramt = PARAMETERS()
 dims = paramt -1
 dimension dimsarr (paramt -1)
 if paramt = 0
    RETURN .f.
 endif
 arrayname = par1
 for counter = 2 to paramt
     paramname = "par"+ STR(counter,1)
     paramvalue = &paramname
     arrayname = arrayname + "_" + LTRIM(STR(paramvalue))
  dimsarr[counter -1] = paramvalue
 next counter
return .t.

func PutArray
 parameters par1, par2, par3, par4, par5, par6, par7, par8, par9
 local paramt, counter, arrayname
 paramt = PARAMETERS()
 if paramt = 0
    RETURN .f.
 endif
 arrayname = par2
 for counter = 3 to paramt
     paramname = "par"+ STR(counter,1)
     arrayname = arrayname + "_" + LTRIM(STR(&paramname))
 next counter
 public &arrayname
 &arrayname = par1
return .t.

func GetArray
 parameters par1, par2, par3, par4, par5, par6, par7, par8, par9
 local paramt, counter, arrayname
 paramt = PARAMETERS()
 if paramt = 0
    RETURN .f.
 endif
 arrayname = par1
 for counter = 2 to paramt
     paramname = "par"+ STR(counter,1)
     arrayname = arrayname + "_" + LTRIM(STR(&paramname))
 next counter
 if type(arrayname) = "U"
  return .f.
 endif
return &arrayname



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Takyan,

Just to add to the good answers you've already received:

In VFP, you can create arrays with one dimenion, or with two dimensions, but no more than two.

Each element of the array can be of a different data type, but an array element cannot itself be an array (that is, VFP does not support Clipper-style 'ragged' arrays).

Hope this helps.

Mike


Mike Lewis
Edinburgh, Scotland
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top