In a Visual Foxpro application one of the users get an error (the rest doesn't). And i开发者_JS百科 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
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.
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.
精彩评论