Visual Foxpro Array [] or ( )

In a Visual Foxpro application one of the users get an error (the rest doesn't). And i believe its because arrays are used in the form of arr(number) instead of arr[number] . Does anyone know what causes this strange behavior at a single user?

Thanks!

Foxpro does not differentiate between the two. This is actually documented in both the DIMENSION and DECLARE commands' remarks.

In fact, the documentation doesn't strictly follow one way or another. The DIMENSION and DECLARE commands define the syntax with parenthesis ().

DIMENSION ArrayName1(nRows1 [, nColumns1]) [AS cType]
   [, ArrayName2(nRows2 [, nColumns2])] ...

But the example provided in the Arrays section of the documentation uses brackets [].

DIMENSION ArrayName[5,2]
ArrayName[1,2] = 966789

Dimension - new Array(), Creates an array of variables. VFP code example. Array with two elements. DIMENSION myArray(2) myArray(  In Visual FoxPro the ALEN function can also return the number of rows or columns in a two-dimensional array. VFP code example DIMENSION myArray(2,3) && create an array of 2 rows and 3 columns

Either use of array references is valid as long as its properly balanced as () or []. The problem is probably upstream where the array is getting declared or prepared. I've had to debug historically strange instances like this where one user was going about a process in a totally different way than others, and the business work flow... Anyhow, because of some "bypassed" process, the array wasn't getting created and thus forced a failure.

Does it always crash at the same location in the process?

I would strongly encourage some error trapping in the process for this "one" user. Worse comes to worse, I would put something in the area of the code something like...

if atc( "PersonsLoginName", sys(0)) > 0
   TurnOnMyCustomDebugging()   && for this special scenario trapping
endif 

Additionally, I don't know what you have for error trapping routines, but I'd get a dump of memory at the time of the error and the full call stack that got the user to that point. If you need help on that, let me know too.

Arrays in C# and VFP, Arrays in C# and VFP. C#. int[] etc, New. VFP. Declare, Dimemnsion, Public Array​. C# Syntax Notes. A number of people have asked me about passing arrays to .NET functions from Visual FoxPro applications. The problem here is that Visual FoxPro arrays are not formatted the right way to just be called to a .NET COM object by default.

I didn't understand why this question was "bumped" from 2010. Maybe because it is kind of "VFP basics" and need details?

Answers are already good. [] and () could be used. It is primarily a preference.

VFP actually doesn't even care if the name denotes and array. It might be a function accepting one or two integer parameters (1..N). However, if there is an array in scope then it takes precedence. Example:

Dimension Dummy[10]
? Dummy[5]    && prints .F. - array members are not initialized
Dummy[2] = 6  && sets array member
? Dummy[2]    && prints 6
Release Dummy && array variable released

? Dummy[5]    && prints 10 - procedure is called
* Dummy[2] = 6  && error - variable does not exists
? Dummy[2]    && prints 4 - procedure is called

Procedure Dummy(tnDim1)
   Return m.tnDim1 * 2
endproc

It wouldn't matter if you used [] or () for an array or function (or procedure - in VFP procedure and function also has no difference, both accept parameters and return result).

As per the OP question, a single user wouldn't have a different result just because [] or () used.

Visual Foxpro Array [] or ( ) - arrays - php, Answers are already good. [] and () could be used. It is primarily a preference. VFP actually doesn't even care if the name denotes and array. It might be a  Visual FoxPro creates an array named MEMVAR if you include the word TO. Include the BLANK keyword to create a set of empty variables. Each variable is assigned the same name, data type, and size as its field.

[PDF] You Need Arrays, Visual FoxPro's arrays are amazingly useful and powerful. This session will So, when you create a 6x3 array in VFP, it can be seen as a one-dimensional  Visual FoxPro 9.0 Language Reference Commands (Visual FoxPro) See Also Supported Visual FoxPro Commands and Functions in OLE DB Provider APPEND FROM ARRAY Command

VFP Array Discussion, Array Manipulation There are some helpful routines that manipulate two dimensional arrays to do both matrix math and more advanced array  VFP actually doesn't even care if the name denotes and array. It might be a function accepting one or two integer parameters (1..N). However, if there is an array in scope then it takes precedence. Example: Dimension Dummy[10] ? Dummy[5] && prints .F. - array members are not initialized Dummy[2] = 6 && sets array member ?

[PDF] Working With Arrays, reason is because in Visual FoxPro, DECLARE is overloaded; it's also used to define the DLLs that an application uses. In VFP, you can also dimension an array  Working With Arrays Doug Hennig This month’s column examines some best practices for working with arrays, including a library routine that does a better job of searching an array than ASCAN and one that cleans up by closing all tables opened by a routine. Although it seems like arrays have been part of FoxPro forever, that isn’t the case.

Comments
  • As far as I know, there is no difference between using [] and (). They can be use interchangeably.
  • What's the error message?
  • The documentation is strictly following a convension in that things between []s are optional parameters, this is nothing to do with the question really.
  • @rudi_visser Please read over that again. If you look at the declaration - ignoring the optional parameters, it uses parens. Then, if you look at the example, it uses square brackets.