The value of a scroll bar can only be integer. Let's suppose you would like to write a program that lets the user select the cost of a meal and then displays the amount of tip. We would like to let the user select an amount from 0 to $100.00. The solution is to make the Maximum value of the scroll bar 10000. When an amount is selected, the value is divided by 100 to give the desired values.
HsbCost with the following properties:
Write the code for the change event on the scroll bar:
Public Class FrmCost 'Programmer: Janet Joy 'Calculate amount of tip Private Sub HsbCost_Scroll(sender As Object, e As ScrollEventArgs) Handles HsbCost.Scroll 'Tip is between 15% and 20% Dim cost As Double = Me.HsbCost.Value / 100 'divide value by 100 to get 2 decimal places Me.LblCost.Text = Format(cost, "$0.00") 'format numbers to 2 decimal places Me.LblTip1.Text = Format(cost * 0.15, "$0.00") '15% tip Me.LblTip2.Text = Format(cost * 0.2, "$0.00") '20% tip End Sub End ClassNotice that if the value selected on the scroll bar is 900, for example, cost will display as $9.00