![]() |
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- |
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- |
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! |
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! |
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! |
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! |
All times are GMT +1. The time now is 11:59 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com