Your problem is that your cursor will be placed at the end of the last two digits in the change event. This is exactly what you do not need. I know there is code to manipulate the cursor, but do you really want to go that route?
Hi Shinehah, Sorry that I am only replying to you now. I have tried several ways to manipulate the cursor, but I think that it will be prone to errors. I have used the masked edit control before, which I see Ryan suggested as well.
On your components tab, right click to add the component, select "Microsoft Masked Edit Control" and add the control to your form. Here are some properties that you will find helpfull with the control, you'll see that it is very similar to a textbox control, just controlling what gets entered into the control.
To clear the Text property when you have a mask defined, you first need to set the Mask property to an empty string, and then the CtlText property to an empty string -
MaskedEdit1.Mask = ""
MaskedEdit1.Text = ""
On your form load event, you can set the Mask property (What You See) to the following-
MaskedEdit1.Mask = "#,###.##" 'The # character allows for only numbers to be added as to where the questionmark (?) allows for only text.
'So, if you want to add a dollar sign ($) in front of the amount you will use it as -
MaskedEdit1.Mask = "?#,###.##"
You can learn much more on the control at the following MS vb6 site -
Labq5, please read all the posts and you will see that we have already covered all possible string functions. When formatting in the change event, the cursor can not be controlled with the format chosen, resulting in incorrect data entered into the textbox.
The maskededit is the only control that can be utilized in this concept.
Andre I tried working with the Mask Control as you suggested. These are some issues I encountered.
- It can not be aligned right justified.
- If I define mask as "#,###.##" it doesn't allow amount greater than 9,999.99 or if I define "#,###,###.##" and I need an amount less than the format it leaves extra commas that I do not need. It allows to type decimals only when you filled up the entire mask or format.
I'm trying to work on a different approach using keypress or keyup. I'll see what I can do.
hi there i just have a problem with my program i used the keycodes of vb wherein every time i enter a letter from A-Z it will display each letter together with a special character " | ". Im done with this but my problem is, the letters were displaying from right to left. please help me with this.
here is my code:
If KeyAscii = 13 Or KeyAscii = 9 Then
surname_txt.Text = StrConv(surname_txt.Text, 1)
If KeyAscii <= 90 Or KeyAscii >= 65 Then
surname_txt.Text = Format(" " & "|" & " " & surname_txt.Text & " ")