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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can scroll bar store decimals?

Status
Not open for further replies.

mattscotney

Programmer
Jul 31, 2002
57
AU
Hi all,

How do I change the type of a horizontal scroll bar value type (hsb.value) so it can accept decimal numbers?

I have tried assigning decimals to the hsb like this:
hsb.value = 3.5 but the value that gets stored in the hsb is 4. How can I make the hsb store decimal numbers?

Thanks :)
 
Hi,

A very crude example illustrating how you can simply multiply/divide by 10^NumberOfDecimals (in your case 10, in my example 100 for 2 decimals) to implement decimals:
form code
------------------------------------------------------
Dim MyScrollBar As New DecimalScrollBar()
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Controls.Add(MyScrollBar)
MyScrollBar.DecimalMaximum = 100
MyScrollBar.DecimalValue = 3.45
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
MessageBox.Show(MyScrollBar.DecimalValue.ToString)
End Sub
------------------------------------------------------

New scrollbar class
------------------------------------------------------
Public Class DecimalScrollBar
Inherits HScrollBar
Const DecFact As Int32 = 100
Public Property DecimalValue() As Single
Get
DecimalValue = Convert.ToSingle(MyBase.Value / DecFact)
End Get
Set(ByVal Value As Single)
MyBase.Value = Convert.ToInt32(Value * DecFact)
End Set
End Property
Public Property DecimalMaximum() As Single
Get
DecimalMaximum = Convert.ToSingle(MyBase.Maximum / DecFact)
End Get
Set(ByVal Value As Single)
MyBase.Maximum = Convert.ToInt32(Value * DecFact)
End Set
End Property
End Class
------------------------------------------------------
You should add error handling, change the DecFact constant to a property with an initial value etc.

Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
In short.... No.

The scrollbar only stores integral values (whole numbers), so you would have to do a trick like Sunaj says and multiply your decimal number by 10 or 100 to make it a whole number.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top