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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cleaning fields with zeroes 2

SitesMasstec

Programmer
Sep 26, 2010
526
Brasil
Hello colleagues!

I have this in a form:
CamposZerados.jpg

I have used a way to blank the field in the third column (when there are zeroes):
Code:
FOR NF=1 TO 12
    strNF=STR(NF,2)
    IF SUBSTR(strNF,1,1)=" "
        strNF="0"+SUBSTR(strNF,2,1)
    ENDIF
    
*  Some commands here

    frase="thisform.txtNFAVRPg" + strNF + ".ForeColor"

    IF YNFAVRPG(NF)<>0.00  
        &frase=RGB(0,0,0)          && Black color
    ELSE
        &frase=RGB(255,255,255)     && White color
    ENDIF
NEXT NF

Is there a neater way to achieve the same result?

Thanks.
 
1. Set Textbox.Format="Z" to display zeros as blank.
You keep forgettinhg things you already knew. We had that - between many other things - in your thread "Numeric data entry from right" https://www.tek-tips.com/threads/numeric-data-entry-from-right-to-left.1829384/post-7568899

You said you set Format to Z in that post. Even without being asked to do so. That's displaying zero values as blank.
 
Your code is fine.

How about this:
Code:
FOR NF = 1 TO 12
    * Format NF as a two-digit number
    strNF = TRANSFORM(NF, "@L 99")

    * Build the object name dynamically
    txtFieldName = "thisform.txtNFAVRPg" + strNF

    * Set the ForeColor property directly
    IF YNFAVRPG(NF) <> 0.00
        EVALUATE(txtFieldName).ForeColor = RGB(0, 0, 0)  && Black color
    ELSE
        EVALUATE(txtFieldName).ForeColor = RGB(255, 255, 255)  && White color
    ENDIF
NEXT NF

Replaced &frase with EVALUATE() -- safer property setting.

Used TRANSFORM() to format NF into a two-digit string, making the code cleaner.

Using EVALUATE() as a direct object reference avoids the need to construct a command string ("frase = "thisform.txtNFAVRPg" + strNF + ".ForeColor"&frase = RGB(255, 255, 255)" <-- Your code is converting a string and then interpreting it at runtime. This is prone to errors if the dynamically constructed string isn't correct.
 
Actually all you need is
Code:
Thisform.Setall("Format","Z","Textbox")
Or set it at designtime. When you have the time to add 1000 textboxes instead of a gird, you also have the time to set their properties.

As you surely have other textboxes apart from the ones in the column that you want to display blank for zeros, you should make use of the third parameter of SetAll to only set it to specific textbox classes, like a numerictextbox class you should design. And then you also wouldn't even need this one line of code, as Format="Z" could be a setting for the numeric textbox class and then you need no code at all.

Also: Use a grid here. In a grid you have to only set Text1.Format="Z" for the column that displays the numeric values. Besides displaying multiple rows just by setting a cursor to the grid.
 
Last edited:
Chris: I use textboxes for data entry and Grid only for displaying data, because I have read about Grid is for data entry (there is a chapter im Kilofox about its complexities), so it's not for me.
Thank you.
 
You meant grid is not for data entry. That's not a black&white truth, and not using a grid, which easily repeats rows, by actually using single controls repeatedly in a form is the bigger sin, if you ask me, than using this excuse to never use the grid for data entry.

Let me make this one step clearer: Even if you take it for granted you only use a grid for displaying data, then you can do a grid for picking the row to edit and give the user the editing in a region of the form next to the grid, just the controls for one record. Picking the row could even be possible with fewer columns per row, when you argue that takes up to much space, or a user could pick from a combobox, which makes it less comfortable but more compact.

Yet another idea: Display the current row in a container you position on top of the grid row having the single set of controls to edit/enter data in there. For the user it could even look, as if there is nothing special about this grid row, though it's not the grid row itself but something put in front of it.

So you can both live by these rules and still not do the sin of having extensive repeats of controls on your form at all.
 
Last edited:
What about the command Blank field <fieldname>


BLANK Command
BLANK [FIELDS FieldList] [DEFAULT [AUTOINC]] [Scope] [FOR lExpression1]

[WHILE lExpression2] [NOOPTIMIZE] [IN nWorkArea | cTableAlias]
 

Part and Inventory Search

Sponsor

Back
Top