Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default SpinButton Rounding Up

I use the following code in a SpinButton. If I manually edit the TextBox1
to 150.25 it is fine but when I use150.6, it rounds the result up and does
not allow the two decial point entry in fact any number over 150.5 turns
to 151. How can I keep the number entered as is without rounding it
up? Not sure which property needs adjusting,

Private Sub SpinButton1_Change()
TextBox1.Text = SpinButton1.Value
End Sub

Private Sub TextBox1_Change()
Dim NewVal As Integer

NewVal = Val(TextBox1.Text)
If NewVal = SpinButton1.Min And _
NewVal <= SpinButton1.Max Then _
SpinButton1.Value = NewVal
End Sub

-Randy-



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default SpinButton Rounding Up

I've skipped the min/max validation, but this approach (or similar) may work
for you:

Private dblMyValue As Double

Private Sub SpinButton1_SpinUp()
dblMyValue = dblMyValue + SpinButton1.SmallChange
TextBox1.Text = dblMyValue
End Sub

Private Sub SpinButton1_SpinDown()
dblMyValue = dblMyValue - SpinButton1.SmallChange
TextBox1.Text = dblMyValue
End Sub

Private Sub TextBox1_Change()
dblMyValue = Val(TextBox1.Text)
If dblMyValue = SpinButton1.Min And _
dblMyValue <= SpinButton1.Max Then _
SpinButton1.Value = dblMyValue
End Sub



"Randal W. Hozeski" wrote in message
news:p3vFb.14921$VB2.33439@attbi_s51...
I use the following code in a SpinButton. If I manually edit the TextBox1
to 150.25 it is fine but when I use150.6, it rounds the result up and does
not allow the two decial point entry in fact any number over 150.5 turns
to 151. How can I keep the number entered as is without rounding it
up? Not sure which property needs adjusting,

Private Sub SpinButton1_Change()
TextBox1.Text = SpinButton1.Value
End Sub

Private Sub TextBox1_Change()
Dim NewVal As Integer

NewVal = Val(TextBox1.Text)
If NewVal = SpinButton1.Min And _
NewVal <= SpinButton1.Max Then _
SpinButton1.Value = NewVal
End Sub

-Randy-





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default SpinButton Rounding Up


This keeping crashing on me @ the following

Private Sub TextBox1_Change()
dblMyValue = Val(TextBox1.Text)
If dblMyValue = SpinButton1.Min And _
dblMyValue <= SpinButton1.Max Then _
SpinButton1.Value = dblMyValue
End Sub

and is not working? The up/down arrow are not
spinning anymore. any idea why?
My code is working fine, scrollwise I just need
it to stop rounding up.
-Randy-


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default SpinButton Rounding Up

That's strange.

I've just created a new workbook, added a userform, added a spinbutton,
added a textbox, copied the code from my last e-mail and ran the form (by
pressing F5)
Worked OK here.

What's you error message?


"Randal W. Hozeski" wrote in message
...

This keeping crashing on me @ the following

Private Sub TextBox1_Change()
dblMyValue = Val(TextBox1.Text)
If dblMyValue = SpinButton1.Min And _
dblMyValue <= SpinButton1.Max Then _
SpinButton1.Value = dblMyValue
End Sub

and is not working? The up/down arrow are not
spinning anymore. any idea why?
My code is working fine, scrollwise I just need
it to stop rounding up.
-Randy-


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default SpinButton Rounding Up


Thanks for the follow up.
I guess that crash is a bad word to use.

When I use your example. It does allow my to use the textbox to
manually change the value, and it does not roundup. (what I requested)
but it does not allow my to use the up/down arrows of the SpinBox. It
just jumps between 1 to -1.

My goal here is to display to the hundredth and increment by .25 When I
created the Spinbutton and double clicked on it to enter the code I only
get a
Private Sub SpinButton1_Change()
which I then replaced with your code. (SpinButton1_SpinUp and SpinDown)
I doubled on the textbox and added the other.

It appears to be close. I just need to get the SpinButons to work.

-Randy-



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default SpinButton Rounding Up

Private Sub SpinButton1_SpinUp()
If Len(Trim(TextBox1.Text)) = 0 Then _
TextBox1.Text = 0
TextBox1.Text = Format(CDbl(TextBox1.Text) + 0.25, "0.00")
SpinButton1.Value = 0
End Sub




Private Sub SpinButton1_SpinDown()
If Len(Trim(TextBox1.Text)) = 0 Then _
TextBox1.Text = 0

TextBox1.Text = Format(CDbl(TextBox1.Text) - 0.25, "0.00")
SpinButton1.Value = 0

End Sub

Worked for me.

--
Regards,
Tom Ogilvy


"Randal W. Hozeski" wrote in message
...

Thanks for the follow up.
I guess that crash is a bad word to use.

When I use your example. It does allow my to use the textbox to
manually change the value, and it does not roundup. (what I requested)
but it does not allow my to use the up/down arrows of the SpinBox. It
just jumps between 1 to -1.

My goal here is to display to the hundredth and increment by .25 When I
created the Spinbutton and double clicked on it to enter the code I only
get a
Private Sub SpinButton1_Change()
which I then replaced with your code. (SpinButton1_SpinUp and SpinDown)
I doubled on the textbox and added the other.

It appears to be close. I just need to get the SpinButons to work.

-Randy-



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



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
Substitute for OLE SpinButton? Daystrom Excel Discussion (Misc queries) 2 January 29th 09 09:10 PM
Spinbutton pcor New Users to Excel 2 November 6th 07 03:16 PM
Spinbutton Ben B Excel Discussion (Misc queries) 3 March 9th 06 11:38 AM
Spinbutton grays out toolbars JSnader Excel Programming 1 November 16th 03 03:26 AM
Spinbutton Linked to Textbox David Reid[_2_] Excel Programming 2 August 19th 03 04:25 PM


All times are GMT +1. The time now is 12:33 AM.

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

About Us

"It's about Microsoft Excel"