Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Performing in textbox calculations
Message
De
09/12/2004 16:11:48
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Performing in textbox calculations
Versions des environnements
Visual FoxPro:
VFP 7 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Divers
Thread ID:
00968132
Message ID:
00968132
Vues:
51
I have written code that calculates an expression typed into a textbox. For example, if I type 122*1.06 into a textbox, it should return 129.32 back into the same textbox. Instead it only returns 129 without the decimals. Any ideas. Also, anyone have a shorter version of this. Here is my code from the valid event of the textbox:
NEWVAL = ""
HELDVAL = ""
CURVALUE = ""
THISVALUE = ALLTRIM(THIS.VALUE)
PLUSMARK = OCCURS("+",THISVALUE)
MINUSMARK = OCCURS("-",THISVALUE)
TIMESMARK = OCCURS("*",THISVALUE)
DIVIDEMARK = OCCURS("/",THISVALUE)
TOTALMARKS = PLUSMARK + MINUSMARK + TIMESMARK + DIVIDEMARK
IF TOTALMARKS > 0
	FOR CALCLOOP = 1 TO LEN(ALLTRIM(THISVALUE))
		CURCHAR = SUBSTR(THISVALUE,CALCLOOP,1)
		DO CASE
		CASE CURCHAR = "+"
			CURSIGN = "+"
			IF EMPTY(HELDVAL)
				HELDVAL = CURVALUE
				CURVALUE = ""
			ELSE
				NEWVAL = VAL(HELDVAL) + VAL(CURVALUE)
				HELDVAL = STR(NEWVAL)
				NEWVAL = ""
				CURVALUE = ""
			ENDIF
		CASE CURCHAR = "-"
			CURSIGN = "-"
			IF EMPTY(HELDVAL)
				HELDVAL = CURVALUE
				CURVALUE = ""
			ELSE
				NEWVAL = VAL(HELDVAL) - VAL(CURVALUE)
				HELDVAL = STR(NEWVAL)
				NEWVAL = ""
				CURVALUE = ""
			ENDIF
		CASE CURCHAR = "*"
			CURSIGN = "*"
			IF EMPTY(HELDVAL)
				HELDVAL = CURVALUE
				CURVALUE = ""
			ELSE
				NEWVAL = VAL(HELDVAL) * VAL(CURVALUE)
				HELDVAL = STR(NEWVAL)
				NEWVAL = ""
				CURVALUE = ""
			ENDIF
		CASE CURCHAR = "/"
			CURSIGN = "/"
			IF EMPTY(HELDVAL)
				HELDVAL = CURVALUE
				CURVALUE = ""
			ELSE
				NEWVAL = VAL(HELDVAL) / VAL(CURVALUE)
				HELDVAL = STR(NEWVAL)
				NEWVAL = ""
				CURVALUE = ""
			ENDIF
		OTHERWISE
			CURVALUE = CURVALUE + SUBSTR(THISVALUE,CALCLOOP,1)
		ENDCASE
	ENDFOR
	FINALCALCSTR = "NEWVAL = VAL(HELDVAL) " + CURSIGN + " VAL(CURVALUE)"
	&FINALCALCSTR
	THIS.VALUE = ALLTRIM(STR(NEWVAL))
	this.SelStart = LEN(this.Value)
ENDIF
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform