Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default Formatting number in a UserForm TextBox

The code below is doing what I want in incrementing an
interest rate in a text box by an 1/8 of a point. I would
like it to always display to 3 decimal places, but it goes:
5.125, 5.25, 5.375, 5.5, dropping trailing zeros.
I know it needs a Format. Any help is appreciated.

Private Sub UserForm_Activate()
txtInterestRate.Value = "5.000"
etc.
------------------------------------
Private Sub spnInterestRate_SpinUp()
txtInterestRate.Value = txtInterestRate.Value + 0.125
End Sub
-------------------------------------
Private Sub spnInterestRate_SpinDown()
txtInterestRate.Value = txtInterestRate.Value - 0.125
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Formatting number in a UserForm TextBox

Private Sub spnInterestRate_SpinUp()
txtInterestRate.Value = format(cdbl(txtInterestRate.Value) _
+ 0.125,"0.000")
End Sub
-------------------------------------
Private Sub spnInterestRate_SpinDown()
txtInterestRate.Value = format(cdbl(txtInterestRate.Value) _
- 0.125,"0.000")
End Sub

--
Regards,
Tom Ogilvy

John Pierce wrote in message
om...
The code below is doing what I want in incrementing an
interest rate in a text box by an 1/8 of a point. I would
like it to always display to 3 decimal places, but it goes:
5.125, 5.25, 5.375, 5.5, dropping trailing zeros.
I know it needs a Format. Any help is appreciated.

Private Sub UserForm_Activate()
txtInterestRate.Value = "5.000"
etc.
------------------------------------
Private Sub spnInterestRate_SpinUp()
txtInterestRate.Value = txtInterestRate.Value + 0.125
End Sub
-------------------------------------
Private Sub spnInterestRate_SpinDown()
txtInterestRate.Value = txtInterestRate.Value - 0.125
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default Formatting number in a UserForm TextBox

Private Sub spnInterestRate_SpinUp()
txtInterestRate.Value = format(cdbl(txtInterestRate.Value) _
+ 0.125,"0.000")
End Sub
-------------------------------------
So, no change in how the initialized value is formatted?
That surprized me. I would never in a zillion years have
been able to come up with this. Well, maybe, someday.
I have seen things like the CDbl but don't know how to
use them, and on this subject, the VBA Help is not helpful
at all. Thanks, Tom. (Do you ever sleep?)
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Formatting number in a UserForm TextBox

cdbl is a conversion function. The value in the textbox is stored as a text
string. Your original code added the number 0.125 to the text string in the
textbox. Excel handles this by doing an implicit conversion to number
(double or single) and adding the 0.125. I just made the conversion
explicit. ( the plus operator is overloaded in that it can be used to do
concatenation - sometimes this causes problems in the situation you have
although apparently it wasn't for you).

for example, from the immediate window:
? "5.000" + "0.125"
5.0000.125
Not what you were doing, but to illustrate.

I don't see any reason to change the initilized value. It shows 3 decimal
places and is a string.

--
Regards,
Tom Ogilvy


John Pierce wrote in message
om...
Private Sub spnInterestRate_SpinUp()
txtInterestRate.Value = format(cdbl(txtInterestRate.Value) _
+ 0.125,"0.000")
End Sub
-------------------------------------
So, no change in how the initialized value is formatted?
That surprized me. I would never in a zillion years have
been able to come up with this. Well, maybe, someday.
I have seen things like the CDbl but don't know how to
use them, and on this subject, the VBA Help is not helpful
at all. Thanks, Tom. (Do you ever sleep?)



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Userform textbox number formats PhilM Excel Discussion (Misc queries) 2 June 7th 06 11:08 AM
userform textbox Phil Excel Worksheet Functions 5 January 16th 05 06:59 PM
Textbox number formatting Mike[_60_] Excel Programming 1 November 14th 03 10:03 PM
formatting text in TextBox in UserForm Kevin Excel Programming 2 November 7th 03 01:34 PM
UserForm TextBox to ActiveSheet TextBox over 256 characters Dan E[_2_] Excel Programming 1 July 28th 03 07:36 PM


All times are GMT +1. The time now is 04:13 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"