Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set Decimal 1

Status
Not open for further replies.

DSTR3

Technical User
Jan 21, 2005
41
0
0
US
I want to have an unbound field where the decimal is set and the display reads. $0.00

So if I type in 1 I get $0.01
To make it $0.10 I would just type in 0....moving the 1 over. To get $1.00 I would type in another 0....so on and so forth.

I need to do this, because I'm using a numberpad on screen and I have to avoid using the decimal point. Any help appreciated.
Thanks
DS
 
Say u have a TextBox called txtDecimal. enter the following code.

Private Sub txtDecimal_AfterUpdate()
Dim strX As String
strX = Left(txtDecimal.Value, Len(Trim _(txtDecimal.Value)) - 2) & "." & Right(txtDecimal.Value, 2)

txtDecimal.Value = Format(strX, "$0.00")
End Sub

hth
steve
 
This works GREAT! Except for one thing. I have a textbox that I want $0.00 to display. And then as I enter the numbers I want to actually see the input. As such.
The Display will be $0.00 I click on the 1 button and the display will read $0.01
I click on the 0 button, he display would then read $0.10
Once again, Thank you,I appreciate your input!
DS
 
hi DS

What you need to do on the form is this.
1. Create a textbox and make the backstyle and borderstyle transparent. also make the forecolor white. This will be named txtHidden.
2. Create a label and make it look like a textbox by setting backcolor to white and specialeffect to sunken. This is named lblDisplay.
2a. Make both TextAlign to Right
3. Make both the same width but make the height of txtHidden about 1mm.
4. Make the tops of both the same and send txtHidden to back of zorder.

Here's the code behind the form. you may need to set the various event properties in the form to EventProcedure.

Option Compare Database
Option Explicit

Private Sub Form_Load()
'set initial value...you set this as required
'you may have an initial value you wish to use
lblDisplay.Caption = Format(0, "$0.00")
End Sub

Private Sub txtHidden_Change()
Dim strX As String

'get length of hidden boxes text
'and adjust output accordingly
Select Case Len(Trim(txtHidden.Text))
Case 0
strX = "0"
Case 1
strX = ".0" & txtHidden.Text
Case 2
strX = "." & txtHidden.Text
Case Else
strX = Left(txtHidden.Text, Len(Trim(txtHidden.Text)) - 2) & "." & Right(txtHidden.Text, 2)
End Select

'display formatted result in label
lblDisplay.Caption = Format(strX, "$0.00")
End Sub

Private Sub txtHidden_GotFocus()
'set cursor location
txtHidden.SelStart = Len(Trim(txtHidden.Text))
End Sub

Private Sub txtHidden_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
'****************************
'ALLOW THESE INPUT CHARACTERS
'****************************
'8=backspace
'9=tab
'46=delete
'37=left arrow/39=right arrow
'48 to 57=numeric digits
Case 8, 9, 46, 37, 39, 48 To 57
'do nothing
Case Else
'reject character and exit
KeyCode = 0
Exit Sub
End Select
End Sub

If set up right you can just see the cursor of txtHidden when it receives focus. you can use this as a guide to editing the output in lblDisplay. Also you may wish to allow more characters to be entered in txtHidden. These can be added to the Select Case structure Have a play about with it and let me know how you get on.

kind regards
steve
 
Many Thanks. I'm going to give it a try, I'll be back with the result. Once again Thank You!
DS
 
Steve,
Works really great, only one problem, I need to input the numbers froma a command button, such as....

Me.TxtHidden = Me.TxtHidden & 1

This works great if you can have focus on the txthidden field.
I can't have focus on any field on the form.

Once again,
Thanks
DS
 
IT WORKS!!!!!!

Private Sub Command3_Click()
Me.TxtHidden = Me.TxtHidden & 1
Dim strX As String

'get length of hidden boxes text
'and adjust output accordingly
Select Case Len(Trim(TxtHidden.Value))
Case 0
strX = "0"
Case 1
strX = ".0" & TxtHidden.Value
Case 2
strX = "." & TxtHidden.Value
Case Else
strX = Left(TxtHidden.Value, Len(Trim(TxtHidden.Value)) - 2) & "." & right(TxtHidden.Value, 2)
End Select

'display formatted result in label
LblDisplay.Caption = Format(strX, "$0.00")
End Sub

I placed this on a command button and this did it!
Once again Thank You so Very Much!!!! This was a very tuff nut to crack and you did it!
DS
 
You know, I thought there was some way of reconizing someone for an exceptional call to duty! Thank you for telling me how! This was my first post.
DS
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top