Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Invisible content of a Textbox

Status
Not open for further replies.

SitesMasstec

Programmer
Sep 26, 2010
546
Brasil
Hello colleagues!

In a Form I have two Textboxes:

[pre]
TEXTBOX ONE TEXTBOX TWO
txtName (Character type) txtBill (Numeric type: 9,999.99)

(blank) 0.00
[/pre]

I wish if the Textbox One is blank I do not want to show the other value inside the Textbox Two, whick carries a 0.00 value. I want the Textbox to be shown, just its contents to be invisible.

Note: I cannot transform the Textbox Two into a character field, because this Textbox is used in calculations.

Thank you,
SitesMasstec
 
First of all you shouldn't use the textbox nor textbox.value in calculations, you should use the bound data in calculations. Controls are controls, they are not variables, you have the most naturaly source of data for your calculations in the data itself, no matter if directly reading from a dbf or if its a dbf you opened (USEd) and bound to a control, that shouldn't interest you, you have the data in the dbf in any case.

Besides that, what you want is a typical accounting notation: negative values in brackets, positive values as is and 0.00 not displayed. That's done via Transform(currencyvalue,"@R (Z"), for example:
Code:
? Transform(-10.00,"@(Z")
? Transform(  0.00,"@(Z")
? Transform( 10.00,"@(Z")

You could set txtBill.controlsource = "(Transform(field,'@(Z'))", with field being the name of the field you want to display.

Bye, Olaf.
 
Hello Olaf!

I made:
A=Transform( 0.00,"@(Z")
B=10
? A+B
Result error: "Operator/operand type mismatch", because A is not a number fit fot calculation.

Thank you,
SitesMasstec
 
What did I say? You shouldn't use the textbox nor textbox.value in calculations, you should use the bound data in calculations

You have a fieldA that is 0.00, fieldB is 10.00. When you display Transform( fieldA,"@(Z"), you still can calculate fieldA+fieldB, they still are the numeric values. txtBill.Value is "", but not fieldA. The display has nothing to do with the calculation. You mix the wrong things and introduce problems you don't need to have.

Bye, Olaf.
 
Hi Olaf!

Problem is that my Form is not bound to any table or cursor. In the Form INIT I have:
[pre]
txtName01=SPACE(10)
txtBill01=0
[/pre]
Thank you,
SitesMasstec
 
You can change the forecolor of txtBill in the InteractiveChange event of txtName, like this
Code:
IF EMPTY(This.Value) &&txtName.InteractiveChnage
	ThisForm.txtBill.ForeColor = ThisForm.txtBill.BackColor
	ThisForm.txtBill.ReadOnly = .T.
ELSE
	ThisForm.txtBill.ForeColor = 0 && Black
	ThisForm.txtBill.ReadOnly = .F.
ENDIF
ReadOnly status was changed to prevent "blind" alteration of txtBill

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania

 
I'm afraid that again means 20 copies of the same code.
First try the Format property. txtBill.Format="Z" should do the same.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top