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!

How to insure textbox value is numeric

Status
Not open for further replies.

Judi201

Technical User
Jul 2, 2005
315
US
Hi!

I have been plagued by this question off and on since I started trying to learn Visual Fox. I create a textbox which will hold a numeric value. On the first pass thru I can use it as a numeric value and all is well. Sometime in the processing, I get an error and the field is now char. This usually happens when I have blanked it out and set focus there to get a new value. I don't want a 0 (zero) to show there so how can I handle this?

Now I have resorted to just testing to see what type it is and acting accordingly but I know there must be a way to force it so I can be sure of what I am getting. The situation that is getting to me is the customer number, a numeric field and used in most queries and indexes so I have to know what I am getting in the VALUE property of the textbox.

I am sure this is something I should know but apparently I don't or can't think of it.

A push in the right direction would be much appreciated.

I tried just making it a char field and always taking VAL but sometimes it shows up numeric and I have the opposite problem.

Judi
 

Judi,

Is the textbox bound to an underlying field?

If not, just set its Value property to 0. You say you don't want the 0 to show. That's easy. Set the Format property to Z (blank when zero).

I suspect that the fact you were "blanking out" the box means you were storing an empty string in it. Thus the character data type.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

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

Thanks for the response. I had tried setting the VALUE to 0 but didn't know how to keep the 0 from showing. You are right that I had been setting the VALUE to "" to clear the box.

The field that I am chasing is not bound. It gets user input for the customer wanted in some cases. This is when my query fails because it compares a numeric field to the now character field from the textbox.

I had about abandoned the input and format properties that I used to use so much in favor of other means (Much of which I modeled after info from "1001 Things...") but I will revisit this.

It seems that I remember 'Z' now that you have told me. By now I should trust that most things I knew before still work. I keep reading that in the forums but somehow this is so new and exciting that I just don't think to go back and look for old ways to solve the problem.

Thanks for all you your help. This app would never have happened without the help I have gotten from this forum.

Judi
 
Mike,

Thanks for that comment. It addresses the next question I have. I had the same idea of making that a mybase class property. Then I hit this situation.

I have a series of 3 text boxes.
Qty on hand && captured from cursor
Qty added && entered by user
New qty && sum of above

So now, if the qty on hand is 0, I loose that when I move from the box. I need it to show up until I confirm the transaction and update the file. Soooo, I am setting the FORMAT property to "" before entering the field and then resetting it after the confirm. This involves several code additions so I am wondering if there is a 'neater' way to do this.

Any suggestions.

Thanks as always.

Judi
 

Judi,

Yes, that's pretty much what I would do. I occasionally remove the formatting (or input mask) while the text box is being edited, and restore it when the editing is finished. In your case, you need to remove it during the editing of the other field, and restore it after the calculation is finished, but I don't see any problem with that.

That said, in this particular case, I might be inclined always to show the 0. I don't know ... it's just that a zero value in quantity on hand is particularly significant. It's not like a report where you've got hundreds of figures, and most of them are zero, so you need to suppress the zeroes.

But you can judge this better than I can.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

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

Yes, that is what I want. I want the 0 to show while it represents a quantity. It is only after updating and refreshing the screen; before a new quantity is displayed, that I want the field blank. I don't want the 0 to appear to be carried forward from last time. This is a quantity that will be 0 many times.

At least, now I know how to handle it and get the appearance I want, thanks to you.

Mike Y. : I am working on that approach. I am spending a few hours with the very worn and appreciated FOXPRO 'Commands and Functions' reading notes and comments I made to myself years ago to try to get some of those things back in my head. I was so overwhelmed by PEM's that it just blew the other right out of my head, I think.[smile]

Mike L's comment to me many months ago (and I have seen it repeated to others) "It will begin to fall into place right away" seemed a long shot until recently when I suddenly realized that when confronted with a new problem my first thought was a visual approach. I felt that maybe I had arrived at that point. Still a long, looong way to go tho.

Many thanks to you all.

Judi
 

Judi,

Mike L's comment to me many months ago (and I have seen it repeated to others) "It will begin to fall into place right away"

Hmm. Did I really say "right away"? I'm not usually that optimistic. Maybe I should've said "eventually".

Still, I can see that you really have come a long way since your original posts last year.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top