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

How to enter number in a textbox in calculator style? 4

Status
Not open for further replies.

Mandy_crw

Programmer
Jul 23, 2020
578
PH
Hi everyone, i have created and app which enters a number format as 100,000.00 which i want to have a calculator style in input... Please help.... thanks...
 
Do you mean you want the digits to be right-aligned? If so, just set the Value property initially to a numeric value.

In general, if a textbox has a numeric Value, or if its ControlSource is a numeric field, the number that you enter will appear right-aligned. The number of decimal places in the Value or field determiens the maximum number of decimal places that can be entered. If the Value or field is character, you can enter any number of digits (subject to the MaxLength property), but these will be left-aligned.

If I have misunderstood the question, please clarify what you mean by "calculator style".

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Mike... the cursor should start at rightmost part of the textbox, and everytime a number is entered number would move to the left.....
 
Mandy, unfortunately that's not quite how it works. If the Value is numeric, the insertion point will start at a point corresponding to the left-most character position of the value. It then stays in that position, with each new character appearing just to the left of the insertion point, pushing those you have already entered towards the left. That behaviour continues until you either exit the control or enter a decmimal point. That's not exactly what you want.

There might be some clever way of getting round that by trapping each keystroke in the KeyPress event and mucking about with the SelStart property, but off-hand I can't see how to do that.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Ok Mike... thank you for always helping me.... God bless....
 
> Hi Mike... the cursor should start at rightmost part of the textbox, and everytime a number is entered number would move to the left.....

Thats how kilofox class works

Best regards
tom

 
Tom, your are right. I've got Kilofix in front of me, and have just found the class you are referring to.

It looks like it would meet Mandy's needs, but there is a lot of code there: something like 150 lines. And it's not simple. The explanation of how it works takes up eight pages. As Andy and Marcia say:

We set out to create a numeric text box, and discovered why none exists. It was HARD!

Mandy, if you are interested in following this up, you could purchase a copy of the book (the one that Tom linked to), and study the techniques described (starting on page 92). But don't expect it to be easy. That's not a reflection on the code or the authors. It's just that it is a difficult problem to solve. Ideally, the behaviour you are looking for should have been built into VFP - it's not an unusual requirement - but that's all history now.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hello,

oh, the first time i disagree with Mike :)

Kilofox comes with a zip to be downloaded.
Unpack it, goto chapter4, open chapter4 project - Form controls, try it.

Maybe its enough to just copy the vcx to your project and use the class txtnumeric in your forms by drag&drop
There is also an update, that means a new version of ch04.vcx with txtnumeric class, not sure whether it was integrated later

Another class for this is mentioned here in chapter 9 :


Regards
tom

Mike is correct : UNDERSTANDING the code is harder :)
 
I didn't look at the kilofox example, but my idea would be to make it a textual textbox, use an input mask with the decimal point and two places for cents (or similar small currency portion) and let programmmatichcaange, interractivechange, and gotfocus call the same user defined method that sets the selstart to the length of the value, so it's forced to the right. To get the numeric value you just use VAL(This.Value) in the valid event, so ensure the inputmask is only allowing entry of digits and has a decimal point the same as SET('POINT') for VAL() to work correct. An inputmask allowing entry up to 999,999.99 would be "###,###,##"

I leave the coding to you, but I think you already have used the kilofox textbox class Tom pointed out.

I'd also try whether the native textbox already behaves good when you set the inital value to a currency type by setting it to $0.00, which might also do what the input mask would do.

Chriss
 

Kilofox comes with a zip to be downloaded.

My mistake, Tom. I understood that Whil had withdrawn the elecronic versions of the book. But I can see the links to download the source code and also a PDF of the book. Thanks for pointing that out.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hello everyone.

I think this class will help. I cant't remember exactly where and when a I got it, but it think it goes as far back as early to mid 2000's.

Setting the .nStyle property, it allows

1) Machine style
2) Calculator style.




Best regards.

Eric J. Muñoz H.
Guadalajara, MX.
 
 https://files.engineering.com/getfile.aspx?folder=89410ab8-1145-41fe-bcee-82bb5bcb30a2&file=txtboxes.rar
Hi trento777... thanks so much... but i do not how to use it... thank you...
 
Hello, Mandy.

Guess you are not familiar with class libraries, then.
Is that so?


Best regards.

Eric J. Muñoz H.
Guadalajara, MX.
 
Trento777... Hi and good day to you... Yes, i do not know what are class libraries and their uses... would you give me an idea? thanks and God bless...
 
Hello Mandy,

I found an easy to implement solution, made by Rick.

Download here

Unpack and add txtboxes.vcx to your project (in classes)
Now in your form drag txtnumber from txtboxes on your form (instead of dragging a textbox from vfp), it gives you a textbox named txtnumber1
Klick on this box and set controls source , inputmask and nstyle according to your needs.

There is also a test form

This maybe the class trento77 is thinking of.

Best regards
tom
 
Thank you, Tom.

That's the very same class lib I originally sent.


Best regards.

Eric J. Muñoz H.
Guadalajara, MX.
 
ok Tom... i will try to study so that i will understand well the class libraries.... Thank you so much...
 
Hello trento777,

sorry, I have read that on tablet and did not see the link, all credits to you

Regards
tom

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top