Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
VFP Bug??
Message
De
16/03/2003 00:51:44
Gerry Schmitz
GHS Automation Inc.
Calgary, Alberta, Canada
 
 
À
15/03/2003 22:28:54
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Titre:
Divers
Thread ID:
00766256
Message ID:
00766266
Vues:
44
Too much information (for me). What are you trying to accomplish ?

The "&" functions as a macro operator ... usually; depends on the context.

In the first part of your message (eg. "someValue &localVarName someOtherValue"), FoxPro is treating &localVarName as a "macro" and is expanding its "contents" (which is "") and including it within the string.

"&" by itself is not treated as a macro; eg. m.a = "a & b" results in "a & b"

To force an "&&" into a string like "Hello && Goodbye" (and avoid an error), you generally need to do something like:

m.a = "Hello" + "&" + "&" + "Goodbye"

If you want to concatenate a macro variable and some other variable/string, then you need a "." (dot) operater; eg.

m.a = "one"
? "&a.two"

... results in "onetwo"; without the ".", Foxpro would treat "atwo" as a variable.

However,

m.a = "&.a"

... simply results in "&.a"

In other cases, when you actually want a "." in the final expression (eg. a Method call), then you need 2 "."; eg.

m.a = "myObject"

&a..Refresh()

... results in myObject.Refresh()

>FoxPro seems to have a problem during a variable assignment when the name of a local (or global) variable is contained within a string literal with a preceding ampersand and succeeding space. "someValue &localVarName someOtherValue"
>
>Can somebody explain??
>
>
>Code summary:
>&& Sample of problem
>Test()
>
>FUNCTION Test()
>  LOCAL localVarName
>  localVarName = ""
>  localVarName = "someValue &localVarName someOtherValue"
> ?localvarName && Possible unexpected results. See detailed code below.
>ENDFUNC
>
>
>My test code and comments below: (If anybody is interested)
>
>TEXT
>	Coding comments:
>	FoxPro seems to have a problem during a variable assignment when the name of a
>	local (or global) variable is contained within a string literal with a preceding
>	ampersand and succeeding space. "someValue &localVarName someOtherValue"
>	
>	The sString assignment seems to have different results based on how the prior sBob variable was assigned.
>	
>	I Don't know if this problem exist in any other version of VFP or do I know if the problem exist
>	with any other possible character\control character other then ampersand.
>	(I'm using vfp beta 8.0., vfp 7.0 is at work - can't test)
>
>	I think the problem exist for public and local variables, as long as the name of the variable
>	is in scope I have run into the problem.
>	
>	The ampersand seems to be the culprit because of, probably, one of 2 things
>	the Macro expansion operator or how &localVarName is being interprited in C or C++.
>	Being the ampersand is the address operator in C or C++,, this would be my guess.
>	This is only a guess.
>
>	I've only this with functions, methods could have different results. (I doubt it)
>
>	Following code displays a possible FoxPro Bug
>ENDTEXT
>
>
>CLEAR ALL
>CLEAR
>
>LOCAL sString as String, sMessage as String, sbob as String
>?SYS(2015) && make sure outPut is different/running each time program has run.
>
>*!*	Run once fore each of the following lines of code.
>*!*	For each of the next two sbob assignments below, the remaining sString assignments will have differnt results
>*!*	based on previous assignment of sbob.
>*!*	The following lines of code will produce different resuls when assigning sString a value.
>*!*	&&sbob = 25  && This sbob assignment will have no effect on the remain sString assignments.
>*!*	&&sbob = ""  && This sbob assignment will cause goofy results in the value of the remaining sString assignments.
>*!*	End - Run once fore each of the following lines of code.
>
>sbob = 25 && This assignment produces expected results in sString assignments.
>*sbob = ""	&& This assignment produces unexpected results in sString assignmets.
>
>
>
>&& Everything is normal
>sCommonMessage = "Value of sSting should equal: " + CHR(10)
>sMessage	=  sCommonMessage + "bob"
>sString 	= ""
>sString 	= "bob" && First Variable assignment
>DisplayMessage(sMessage, sString)
>
>
>&& *** Here is where the problems begins
>&& From this point forward I had to format the assignment of variable 'sMessage' for output. (Because of possible bug)
>
>&& If the data type of variable sbob is anything other then char or string then behavior
>&& of sString seems to be as expected.
>sMessage	=  sCommonMessage + "string literal w/ampersand  and varname at end of string &" + "sbob"
>sString 	= ""
>&& Results of this next assignment will be different based on how the variable sbob was initialized
>&& If sbob was initialized as anything other then char or string, we should be fine.
>&& Otherwise code seems to strip the word sbob from string literal
>sString 	= "string literal w/ampersand  and varname at end of string &sbob"
>DisplayMessage(sMessage, sString )
>
>
>sMessage 	= 	sCommonMessage + "s&" + "sbob Some Other String"
>sString 	= ""
>&& The value 'sbob' is near beginning of string literal assigned to variable sString.
>&& The 'sbob' in string literal is still stripped during assignment,
>&& everything else stays.
>&& Tested to see if placement of "&sbob" made a difference, Nope it didn't.
>sString 	= "s&sbob Some Other String"
>DisplayMessage(sMessage, sString)
>
>
>sMessage 	= 	sCommonMessage + "s&" + "sbobSome other literal behind sbob"
>sString 	= ""
>&& since there isn't a space after sString no problems are encountered.
>sString 	= "s&sbobSome other literal behind sbob"
>DisplayMessage(sMessage, sString)
>
>
>
>
>&& Function to display a common output.  Could also run in debugger, Same results
>FUNCTION DisplayMessage(sMessage as String, sVariable as String) as VOID
>LOCAL sCommonMessage as String
>*!*		sCommonMessage = IIF(TYPE("sbob") $ "U","Local ", "Global ") + "Variable sbob Declare. "
>PrintText("*****************************************")
>	PrintText(sMessage)
>	PrintText("Variable value: ")
>	PrintText(sVariable)
>	PrintText("*****************************************")
>*!*		PrintText(CHR(10))
>ENDFUNC
>
>&& Function for formatting during code output.
>&& May help readablity
>FUNCTION PrintText(sValue as String, nIterations as Number) as VOID
>LOCAL i as Number
>	IF TYPE("nIterations") # "N"
>		nIterations = 1
>	ENDIF
>	
>	FOR i = 1 TO nIterations
>		?sValue
>	ENDFOR
>ENDFUNC
>
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform