Link to home
Start Free TrialLog in
Avatar of blacklord
blacklord

asked on

Simple Textbox question

Is it possible to use the Maskedbox change event for formatting the data while it is typing?  For example If I use the code below I cannot enter this value into the textbox with or without sendkey, 1.450,45 because comma and dot is not working for the decimal value. On the other hand, If I use maskedbox it is not formatting the values while it is typing. And it become very difficult when you are working with large numbers.

Private Sub Text38_Change(Index As Integer)
Text38(4).Text = Format(Text38(4).Text, "###,###.00")
SendKeys "{End}"
End Sub

vb6.0
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

try NOT format your text value in the Change event, try do in in LostFocus or KeyDown event instead.. ?
Avatar of anv
anv

>>maskedbox it is not formatting the values while it is typing. And it become very >difficult when you are working with large numbers

hi

when u r using Masked edit box..

set the Mask property (at Design Time) to ###,###.00

now user will type only in the desired format...

Avatar of blacklord

ASKER

Then it become very difficult. Because I am talking about the millions. You have to see what your are typing.
Best would be to add the format text in the validate event of the text box...
if I set the mask property to ###,###.00, then the user should enter only 6 digit values. not more  or less. Like 12.345.678,45 or 3.456,78
thanks...
hi blacklord

i'm not getting what are u talking about??

Please explain...

as in my first post i gave u th e solution for masking using maskediit box..

after ur comment i asked u to add the text box shift evnet code to validate event

now u 've posted for the maskedit box... what are u trying to convey?? please explain..
If I use maskedbox I can only see the formatted values after typing (Lostfocus event).  I have to see the proper format while the user types.
I can see it if I am using textbox. But when I use the text box I cant enter the values like 2 decimal values like currency. I am using the code below to format the text box while its typing.

Private Sub Text38_Change(Index As Integer)
Text38(4).Text = Format(Text38(4).Text, "###,###.00")
SendKeys "{End}"
End Sub


Now as a result;
In maskedbox: I can format and enter what I want but except  in 'change' event.
In Text Box: I can't enter currency format If I use the code, but I can use the text1_change event.

Hope this helps...
I also tyried the validate event. Didnt work like I want. Thanks...
hi blacklord

i feel u r missing something here..

the thing is when u use maskedbox...the actual format is being displayed when user types in the values...
u dont have to use any event like change etc... for changeing the format...

just add the format to the mask property of the masked edit box...at design time..

now when u run the project ..

u would see..(if u have  given the mask as ###,###.00) as
___,___.00

i suppose this is what u want to display to the user..??

i hope i'm not misunderstanding ur question..

 

okey thats good but how can the user type the number 12435.678,76 with this mask? I dont want to retrict this input area by mask. The user be able to enter millions or only the cent.
Thanks...
hi blacklord..

u can use...9's in place of #'s

9 => is an optional number value

instead of text or formattedText or any other property to get the vlaue entered in the control use 'ClipText' property ..which will give the exact value entered by the user...

Thanks any for help... But I cant understand. I am using 9 's in maskedbox but I still cant enter this value 1.000.000,56 and the user should type this 002.556,23 to write 2.556,23
hi blacklord

give the maximum limit in the masked edit box...

like...if u want to add 1.000.000,56  or more value use

9.999.999,999,99  ........

its because...by doing this.. masked edit will alllow u to enter less values..but not more than the limit..

ok, but think about flexibility and efficiency, masked this field for currency is not very good. Because for example to enter 1.456,34:

mask: 9.999.999.999.999,99
Value:0.000.000.001.546,34

user must enter this kind of value.
I don't believe you can do this with a masked edit box, as the mask is fix there, it accepts characters only in a specific location (from left to right), which you can't give because you don't know how big the number will get.

Perhaps you'll have to create you own textbox that mimics that behaviour by processing the numbers from left to right while typing. But I believe if you allow the user to edit the number by removing or adding numbers in the right in the middle, might make this very complicated as you'll then have to rewrite the whole number AND remember where the cursor stood.
Would there be a different component for that kind of purpose? Because I saw it once in a program.

What I need to do is format the value within the change event and also the user be able to insert comma to for decimal values. I can not make it with the following code.

Private Sub Text38_Change(Index As Integer)
Text38(4).Text = Format(Text38(4).Text, "###,###.00")
SendKeys "{End}"
End Sub
Dim bFromCode As Boolean

Private Sub Form_Load()
   Text1.Alignment = 1
   Text1 = 0
End Sub

Private Sub Text1_Change()
   If bFromCode Then Exit Sub
   bFromCode = True
   Text1.Text = Format(Text1.Text, "###,##0.00")
   Text1.SelStart = 0
   bFromCode = False
End Sub
ark thanks for the answer but still it is not working

can anybody tell me how to format that value while I am typing into the textbox?

thanks

1,234,456,657.98
ASKER CERTIFIED SOLUTION
Avatar of Ark
Ark
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial