|
-
Aug 5th, 2005, 05:00 PM
#1
Thread Starter
New Member
Trouble formatting currency
I am having trouble formatting currency in a textbox.
What I want is when the user enters a digit it appends it in the textbox with a .00. So if I enter a 2 it would look like 2.00 in the textbox. The problem I am having is when I add more digits it does not display them right. For example lets say I want to enter 235.00. When I enter a 2 it looks like this:
2.00. When I enter the 3 it looks like this: 32.00 and when I enter a 5 it will look like this: 352.00. Here is the piece of code I am using to format:
VB Code:
Private Sub txtDispense_Change()
txtDispense.Text = Format(txtDispense, "fixed")
End Sub
Any help would be much appreciated
-
Aug 5th, 2005, 05:15 PM
#2
Re: Trouble formatting currency
Try using the masked edit control. It should do what you want.
This one formats phone numbers, but you could change it to whatever you want.
http://vbforums.com/attachment.php?attachmentid=38605
-
Aug 5th, 2005, 05:27 PM
#3
Re: Trouble formatting currency
maybe you could format the text box once it has lost focus?
VB Code:
Private Sub txtDispense_Lost_Focus()
txtDispense.Text = Format(txtDispense, "fixed")
End Sub
-
Aug 5th, 2005, 06:49 PM
#4
Re: Trouble formatting currency
Everytime you set the Text property in code, the caret is re-positioned to the beginning.
To work around this issue you can manually re-position the caret again after formatting the data.
VB Code:
Private Sub txtDispense_Change()
Dim lngPos As Long
lngPos = txtDispense.SelStart
txtDispense.Text = Format(txtDispense, "fixed")
txtDispense.SelStart = lngPos
End Sub
-
Aug 6th, 2005, 01:00 PM
#5
Thread Starter
New Member
Re: Trouble formatting currency
Thanks that worked perfect.
Post resloved.
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
|