Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Null values in a textbox
Message
From
23/08/2002 13:33:31
Fabian Valencia
Calamos Asset Managment Inc.
Naperville, Illinois, United States
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Title:
Null values in a textbox
Miscellaneous
Thread ID:
00693042
Message ID:
00693042
Views:
72
Whenever you want to use a textbox for numeric data you can have a problem with null values.
Ex. I have a form with a textbox whose inputmask is 999.99 and I set the value of the textbox to 0.
I can go into the textbox and change the number and the vartype remains numeric. I also have a button on the form that sets the textbox.value to .null. Now if I try to change the data in the textbox say by typing 123.45
the textbox.value type has changed to character. If I assign a controlsource then I can type a number in the textbox but it remains a character datatype.

I have a fix for it. Below is the code for the class, take it and try it out.
Before you run the code set nulldisplay to 'n/a'.
Simply type a number in the textbox to insure that you can enter a number. The label to the right shows the datatype. Now press the set to null button and the textbox display changes to n/a. Now try and type a number like 123.45.
The value is now character.

To apply the fix simply uncomment the valid and the interactive change methods and retry the code. Now no matter what you do the data remains numeric.

If anyone sees a problem with this or has any other suggestions please let me know

Thanks

The code is as follows

**************************************************
*-- Class: frmtestnull (h:\dev\bill\testnull.vcx)
*-- ParentClass: form
*-- BaseClass: form
*-- Time Stamp: 08/23/02 12:14:14 PM
*
DEFINE CLASS frmtestnull AS form


DoCreate = .T.
AutoCenter = .T.
Caption = "Form1"
rntextvalue = 0
Name = "frmtestnull"


ADD OBJECT ccommandbutton1 AS ccommandbutton WITH ;
Top = 96, ;
Left = 216, ;
Caption = "set to null", ;
Name = "Ccommandbutton1"


ADD OBJECT ctextbox1 AS ctextbox WITH ;
Alignment = 1, ;
Value = 0, ;
ControlSource = "", ;
InputMask = "999.99", ;
Left = 120, ;
Top = 48, ;
Name = "Ctextbox1"


ADD OBJECT ccommandbutton2 AS ccommandbutton WITH ;
Top = 96, ;
Left = 96, ;
Caption = "set to 0", ;
Name = "Ccommandbutton2"


ADD OBJECT label1 AS label WITH ;
Caption = "", ;
Height = 17, ;
Left = 216, ;
Top = 52, ;
Width = 84, ;
Name = "Label1"


PROCEDURE ccommandbutton1.Click
*thisform.rnTextValue = .null.
Thisform.ctextbox1.Value = .null.
Thisform.Refresh()
ENDPROC


PROCEDURE ctextbox1.InteractiveChange
*!* IF VARTYPE(This.Value) = 'C'
*!* This.Value = VAL(This.Value)
*!* KEYBOARD ALLTRIM(STR(This.Value))
*!* ENDIF
ENDPROC


PROCEDURE ctextbox1.Valid
&& This happens if the value was .null. and they typed in a character and then exited the field
&& or if the text box has a controlsource
*!* IF VARTYPE(This.Value) = 'C'
*!* This.Value = VAL(this.Value)
*!* IF NOT EMPTY(This.ControlSource)
*!* cControlSource = This.ControlSource
*!* &cControlSource = This.Value
*!* ENDIF
*!* ENDIF
Thisform.label1.Caption = VARTYPE(this.Value)
ENDPROC


PROCEDURE ccommandbutton2.Click
*thisform.rntextValue = 0
Thisform.ctextbox1.Value = 0
Thisform.Refresh()
ENDPROC


ENDDEFINE
*
*-- EndDefine: frmtestnull
**************************************************
Next
Reply
Map
View

Click here to load this message in the networking platform