Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
VFP Bug??
Message
De
15/03/2003 22:28:54
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Titre:
VFP Bug??
Divers
Thread ID:
00766256
Message ID:
00766256
Vues:
99
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 
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform