×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

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

How to enter number in a textbox in calculator style?

How to enter number in a textbox in calculator style?

(OP)
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...

RE: How to enter number in a textbox in calculator style?

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

RE: How to enter number in a textbox in calculator style?

(OP)
Hi Mike... the cursor should start at rightmost part of the textbox, and everytime a number is entered number would move to the left.....

RE: How to enter number in a textbox in calculator style?

2
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

RE: How to enter number in a textbox in calculator style?

(OP)
Ok Mike... thank you for always helping me.... God bless....

RE: How to enter number in a textbox in calculator style?

I wasn't much help, Mandy. Maybe somebody else here will have some good ideas. I'd be curious myself to know if there is a solution.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: How to enter number in a textbox in calculator style?

> 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

RE: How to enter number in a textbox in calculator style?

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:

Quote:

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

RE: How to enter number in a textbox in calculator style?

Hello,

oh, the first time i disagree with Mike smile

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 :
https://www.hentzenwerke.com/catalog/efftech.htm
https://www.hentzenwerke.com/samplechapters/et2_sc...


Regards
tom

Mike is correct : UNDERSTANDING the code is harder smile

RE: How to enter number in a textbox in calculator style?

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

RE: How to enter number in a textbox in calculator style?


Quote:

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

RE: How to enter number in a textbox in calculator style?

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.

RE: How to enter number in a textbox in calculator style?

(OP)
Hi trento777... thanks so much... but i do not how to use it... thank you...

RE: How to enter number in a textbox in calculator style?

Hello, Mandy.

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


Best regards.

Eric J. Muñoz H.
Guadalajara, MX.

RE: How to enter number in a textbox in calculator style?

(OP)
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...

RE: How to enter number in a textbox in calculator style?

Hello Mandy,

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

Download here
https://www.levelextreme.com/Home/ShowHeader?Activ...

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

RE: How to enter number in a textbox in calculator style?

Thank you, Tom.

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


Best regards.

Eric J. Muñoz H.
Guadalajara, MX.

RE: How to enter number in a textbox in calculator style?

(OP)
ok Tom... i will try to study so that i will understand well the class libraries.... Thank you so much...

RE: How to enter number in a textbox in calculator style?

Hello trento777,

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

Regards
tom

RE: How to enter number in a textbox in calculator style?

Hello, Tom.

It's not about getting the credits, it's about helping others and I'm really glad you remembered the original link to it. Also, it provides a sample form, so it will make it easier for others to understand and try it in advance.



Best regards.

Eric J. Muñoz H.
Guadalajara, MX.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close