|
-
Aug 10th, 2012, 05:20 AM
#1
Thread Starter
Lively Member
How Can I create a TextBox with Digit Group option
hi friends....
I want to create a textbox like Windows XP Calculator's textbox by this condition:
1 -the digits separate by comma (digit Grouping) like Windows XP Calculator's textbox
2 -the decimal part of number don't get digit group option .
example of this textbox format :
1,234,567.6576
0.2123423423423423
-1,2332,33.232023
-
Aug 10th, 2012, 06:27 AM
#2
Re: How Can I create a TextBox with Digit Group option
I suggest using the custom control that I created and have already directed you to.
http://www.vbforums.com/showthread.p...Box&highlight=
-
Aug 11th, 2012, 05:20 AM
#3
Thread Starter
Lively Member
Re: How Can I create a TextBox with Digit Group option
 Originally Posted by jmcilhinney
hi and thanks...
your example is for vb but i want do this in vb.net
-
Aug 11th, 2012, 05:43 AM
#4
Re: How Can I create a TextBox with Digit Group option
Why would I have posted it in the VB.NET CodeBank forum if it wasn't for VB.NET? Why would I say in that thread:
Note that the code was written in VB 2008.
if it wasn't for VB.NET? Why would I have suggested it in the first place if it wasn't for VB.NET? With 76,000 posts, do you really think that I don't know the difference?
-
Aug 11th, 2012, 07:41 AM
#5
Thread Starter
Lively Member
Re: How Can I create a TextBox with Digit Group option
oh...it's my fault . i have no mean.sorry
i saw the extention (.vb)
accept my apologise please
-
Aug 11th, 2012, 09:26 AM
#6
Re: How Can I create a TextBox with Digit Group option
Accepted.
-
Aug 12th, 2012, 09:05 AM
#7
Thread Starter
Lively Member
Re: How Can I create a TextBox with Digit Group option
hello again...
i exec your program.it's perfect .but a problem remaine for me and i know it's my problem.however i discuss it.i want that each time i press a key to input a number , the output change to form that i want.
an example :
keypress=1
output=1
keypress=2
output=12
keypress=3
output=123
keypress=4
output=1,234
keypress=.
output=1,234.
keypress=2
output=1,234.2
please help me.
-
Aug 12th, 2012, 09:40 AM
#8
Re: How Can I create a TextBox with Digit Group option
That might seem like a good idea but it's not if you're using it as a regular TextBox, i.e. where the user can place the caret anywhere to insert or delete text. Trust me, I wrestled with that myself when creating that custom control and decided that there was just no good way to handle it. The difference with the display in the Windows calculator is that it is NOT a TextBox. It's basically just a Label. The application itself detects the key presses and simply appends the appropriate character(s) to the end of the text. There are no insertions and deletions in the middle of the text, only appending and removing from the end. So, which is it that you want? If you want to be able to insert then I suggest that you give up on dynamic formatting and I for one will not be helping because I've already tried and found no solution acceptable in all circumstances. If it's the latter then this whole thing would need to be handled quite differently.
-
Aug 13th, 2012, 09:31 PM
#9
Thread Starter
Lively Member
Re: How Can I create a TextBox with Digit Group option
hi and sorry for delay...
i am so confuse about it. so you think that calculator of windows has no textbox? and in fact it is a label?
that's a little complicated.however thanks.your guidance is very useful for me. and sorry about that topic again.
-
Aug 13th, 2012, 09:49 PM
#10
Re: How Can I create a TextBox with Digit Group option
The Windows Calculator applet is not a .NET app so it wouldn't use .NET Labels and TextBoxes anyway but think about how you use a TextBox, e.g. typing into the middle of the text and also deleting from the middle of the text. Does the Windows Calculator work that way? No it doesn't. So, which way do you want your control to work?
-
Aug 13th, 2012, 11:06 PM
#11
Lively Member
Re: How Can I create a TextBox with Digit Group option
I actually ran into something similar, but it was for phone numbers. The way I went about it, but as an approach to your issue.
First check onkepress which key is being pressed. If the key falls between ascii code for number 0-9 or key is ascii decimal code proceed, otherwise exit sub.
Create a function that formats the number for you.
Create a variable which holds the textbox value
Code:
dim unformatNum as string
Extract the decimal and everything to the right from unformatNum. Store this in a variable
Code:
DIM rightOfDec as string
Your unformatNum should now be without decimal value.
Create another variable to hold the "," commas' index number
Code:
DIM comIndex as integer
Set this variable to equal textbox.length - rightOfDec.length - 1 ( the "-1" is your offset).
Create a loop to run in the loop insert your comma in unformatNum at index position comIndex. Subtract 3 from comIndex. Let loop iterate.
You should now end up with a comma formatted number. Append your rightOfDec value.
NOTE: This should guide you to the solution. This was off the top of my head from what I remember of my solution. Now, for my scenario i have it set to run the ascii checker on key press, then format a number as it's typed into a phone number so 8007765208 will become (800)776-5208. There is problem here. As you type the procedure may not have finished processing when it starts handling your next key press. So I had to check for this, and cancel the last call. Otherwise bad times.
Another option is to have the textbox read only and capture the keystrokes. You can place a border color around the box to let the user know it has focus.
If you need more help with it, I do have another solution. I created a dll that actually formats numbers the way you seek, including negative numbers and dollar signs if dealing with money. To use you will instantiate a hltools object, pass the string and an optional bool if you are dealing with money. Now this is in beta but it works very good as far as I remember. I haven't used or worked on it in about 1 year (I been busy). Its written in c++. The dll also has a few other useful tools that are in this same type category (such as reversing the process: $233,990.45 -> 233990.45). You can also specify the number of digits to right of decimal if I remember correctly. I did this during my first semester in school because I got tired of retyping the same dam formatter procedures over and over, only to modify a line or two.....
Last edited by elielCT; Aug 13th, 2012 at 11:13 PM.
Reason: Minor edits. nothing special
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|