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

Problem with Z format 1

Status
Not open for further replies.

Judi201

Technical User
Jul 2, 2005
315
US
Hi!

I can't believe I am having this much trouble with this. I have a textbox for entering a customer number. I want to set the value of the field 0 and use the Z in the format to keep the 0 from showing when the textbox gets focus. I know I have done this before. In fact I just reread a thread where people on this forum discussed doing this with me!

Now I can't get that to work. I was using a textbox class that does some formating of input so I thought maybe that was the problem. I went back to the basic textbox and get the same results. The 0 shows no matter what I try!!

I recently moved to VFP 9 but can't see why that would matter. I have not gone back through every screen to see if other places are maybe not working but thought I would ask it maybe someone could suggest something I might look for to correct this problem.

Is there any setting that might over-ride this behavior or something?

Thanks for any ideas.

Judi
 

Judi,

Check that the textbox has a numeric value. It should either be bound to a numeric field, or have a numeric value as its starting value.

If it contains a character value (including "(None)"), the Z will be ignored.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike,
Thanks for the reply. The textbox is not bound and has a 0 in the value property. You had helped me with this before where I was trying to refresh the screen to start a new entry and I did it in code.

I went back to see if this coding was still working and it is fine. This time I need it to initialize as a blank textbox holding a value of 0. Am I wrong in thinking that I should be able to expect this to be set in form design?

If I need to :
Code:
Thisform.pgfTickets.pagPayment.txtCustno.Format = "Z"

where would I put it?

Many thanks for all help.

Judi
 

Judi,

You should certainly be able to do it in the form designer.

The following should work:

1. Create a form.

2. Add a text box.

3. In the property window, set the textbox's value to 0 and its format to Z.

That's all you need to do.

However, keep in mind that the "blank when zero" only works while the text box does not have focus. As soon as you put focus on the textbox, the zero will show up; it will disappear again when you put focus somewhere else. This is the normal behaviour, as it would be tricky to edit the value otherwise. (This doesn't apply if the textbox is read-only.)

Does that help at all?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike,

As always, right on target. The SefFocus issue is what I was not considering.

So, if the textbox is the first tab order on the page then it would have focus when it comes visible?

If so, may I ask how you would handle this situation? Or, should I leave it blank and deal with the numeric value in code in LostFocus? This was what I had been doing but somehow I seemed to always be running into the value changing on me.

Any suggestions appreciated.

Judi
 
Judi,

if the textbox is the first tab order on the page then it would have focus when it comes visible?

That's correct.

If you definitely must have the text box as the first control in tab order, I'm not sure what you can do about that. The only thing that comes to mind is to convert the value to a string in the text box's GotFocus, and to convert it back to a number in the LostFocus. Something like this:

Code:
* GotFocus
this.Value = ALLTRIM(TRANSFORM(this.Value, "@Z"))
..
* LostFocus
this.value = VAL(this.value)

But then the user will be editing a string rather than a number, with all that that implies. But it migth be worth experimenting along those lines.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike,

Thanks, I will proceed along those lines.
Appreciate your help.

Judi
 
Mike,

I just noticed that you included the @ in the format. I know this was done in 2.6 but had not seen it anywhere in help now. What is the significance of the @ in your code?

Thanks

Judy
 
Mike,

Sorry, I went back to help to look at TRANSFORM() and found the @Z. I was still thinking FORMAT I guess. Oh well.

Thanks again for all of your help.

Judi
 

Judi,

My understanding is that the @ is optional in the Format property, or in the Format clause of an @/GET, but it is required in TRANSFORM() -- but I'm not completely sure about that.

I guess the reason is that, in TRANSFORM(), the format code has to be distinguished from the "picture" code. For example, if the code is "!", that would be taken to mean you want to upper-case just the first character of the field, whereas "@!" refers to the whole field.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike,

Makes sense. Anyway, I have used your idea and have it working as I want, neat, clean and so far my value has been numeric every where I use it so I am happy with that.

I have the functionality of my app in place and working nicely now I am working on some cosmetics before moving on. It seems like a life-time ago when I asked the first question here and you (and some others) so patiently led me into the OOP world.

Many thanks.

Judi
 

Judi,

Delighted to hear your app has progressed so far. It must be about a year now since your first posts in this forum. I notice that you've been answering other people's questions recently, as well as posting your own, so the learning process must be going well.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike,

Yes, I think so. I haven't answered many because you experts are so quick and know so much more than I do. But I watch and read and if one comes on the isn't answered immediately I will certainly give it a shot. Hope before long I can do more.

Judi


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top