Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Textbox numeric formatting
Message
De
17/11/2014 15:58:41
 
 
À
17/11/2014 07:08:20
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01611077
Message ID:
01611119
Vues:
128
Below is a export of a class that I have defined for inputting numeric values into a text box. I have an input mask that is two decimals for a currency input; however, you could add a property that controls the number of decimals and then determine the input mask at run-time based on size. You will also need to replace the calls to my UDF for displaying a message to the user.
**************************************************
*-- Class:        _currency (e:\my work\foxpro\projects\gkkmembership\classes\baseclasses.vcx)
*-- ParentClass:  textbox
*-- BaseClass:    textbox
*-- Time Stamp:   10/02/14 09:57:02 PM
*
*
DEFINE CLASS _currency AS textbox


	Alignment = 1
	Value = 0.00
	Height = 23
	SelectOnEntry = .T.
	Width = 100
	*-- Amount entered
	amount = 0.00
	*-- XML Metadata for customizable properties
	_memberdata = [<VFPData><memberdata name="amount" type="property" display="Amount"/><memberdata name="amount_assign" type="method" display="Amount_Assign"/><memberdata name="uservalid" type="method" display="UserValid"/><memberdata name="allowzero" type="property" display="AllowZero"/><memberdata name="maxamount" type="property" display="MaxAmount"/><memberdata name="addcurrencysymbol" type="property" display="AddCurrencySymbol"/><memberdata name="currencysymbol" type="property" display="CurrencySymbol"/></VFPData>]
	*-- Flag to indicate if zero is a valid entry
	allowzero = .F.
	*-- Maximum amount if greater than 0.00
	maxamount = -1
	*-- Flag to indicate whether to add the currency symbol to the value
	addcurrencysymbol = .F.
	*-- Currency Symbol
	currencysymbol = "$"
	Name = "_currency"


	PROCEDURE amount_assign
		LPARAMETERS tnAmount
		this.InputMask = ''
		DO CASE
			CASE VARTYPE(tnAmount) = "N"
				this.Amount = tnAmount
				this.Value  = IIF(this.AddCurrencySymbol, this.CurrencySymbol+" ", "") + ALLTRIM(TRANSFORM(tnAmount, "9,999,999.99"))

			CASE VARTYPE(tnAmount) = "C"
				this.Amount = VAL(ALLTRIM(tnAmount))
				this.Value  = IIF(this.AddCurrencySymbol, this.CurrencySymbol+" ", "") + ALLTRIM(TRANSFORM(tnAmount, "9,999,999.99"))

			OTHERWISE
				WAIT WINDOW "Invalid value entered for Amount" NOWAIT
		ENDCASE
	ENDPROC


	PROCEDURE GotFocus
		SET CURSOR ON
		this.InputMask = '9999999.99'
		this.Amount = this.Amount
	ENDPROC


	PROCEDURE Valid
		LOCAL lnAmount
		DO CASE
			CASE VARTYPE(this.Value) = "N"
				IF this.Value > 0.00
					IF this.MaxAmount < 0.00
						this.Amount = this.Value
						this.UserValid()
					ELSE
						IF this.Value <= this.MaxAmount
							this.Amount = this.Value
							this.UserValid()
						ELSE
							DisplayMsg("Value entered cannot be greater than $ " + ALLTRIM(TRANSFORM(this.MaxAmount, "9,999,999.99")))
							this.Amount = this.MaxAmount
							RETURN False
						ENDIF
					ENDIF
				ELSE
					IF this.AllowZero .AND. this.Value = 0.00
						this.Amount = this.Value
						this.UserValid()
					ELSE
						DisplayMsg("Invalid value entered")
						RETURN False
					ENDIF
				ENDIF

			CASE VARTYPE(this.Value) = "C"
				lnAmount = VAL(STRTRAN(STRTRAN(this.Value, ",", "") , "$", ""))
				IF lnAmount > 0.00
					IF this.MaxAmount < 0.00
						this.Amount = lnAmount
						this.UserValid()
					ELSE
						IF lnAmount <= this.MaxAmount
							this.Amount = lnAmount
							this.UserValid()
						ELSE
							DisplayMsg("Value entered cannot be greater than $ " + ALLTRIM(TRANSFORM(this.MaxAmount, "9,999,999.99")))
							this.Amount = this.MaxAmount
							RETURN False
						ENDIF
					ENDIF
				ELSE
					IF this.AllowZero .AND. lnAmount = 0.00
						this.Amount = lnAmount
						this.UserValid()
					ELSE
						DisplayMsg("Invalid value entered")
						RETURN False
					ENDIF
				ENDIF

			OTHERWISE
				DisplayMsg("Invalid value entered")
				RETURN False
		ENDCASE
	ENDPROC


	*-- Called by Valid event for user code
	PROCEDURE uservalid
	ENDPROC


ENDDEFINE
*
*-- EndDefine: _currency
**************************************************
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform