Max, Min Properties

Applies To

ScrollBar control, SpinButton control.

Description

Specify the maximum and minimum acceptable values for the Value property of a ScrollBar or SpinButton.

Syntax

object.Max [= Long]

object.Min [= Long]

The Max and Min property syntaxes have these parts:

Part

Description

object

Required. A valid object.

Long

Optional. A numeric expression specifying the maximum or minimum Value property setting.


Remarks

Clicking a SpinButton or moving the scroll box in a ScrollBar changes the Value property of the control.

The value for the Max property corresponds to the lowest position of a vertical ScrollBar or the rightmost position of a horizontal ScrollBar. The value for the Min property corresponds to the highest position of a vertical ScrollBar or the leftmost position of a horizontal ScrollBar.

Any integer is an acceptable setting for this property. The recommended range of values is from –32,767 to +32,767. The default value is 1.

Note Min and Max refer to locations, not to relative values, on the ScrollBar. That is, the value of Max could be less than the value of Min. If this is the case, moving toward the Max (bottom) position means decreasing Value; moving toward the Min (top) position means increasing Value.

See Also

LargeChange property, SmallChange property, Value property.

Example

The following example demonstrates the Max and Min properties when used with a stand-alone ScrollBar. The user can set the Max and Min values to any integer in the range of –1000 to 1000. This example also uses the MaxLength property to restrict the number of characters entered for the Max and Min values.

To use this example, copy this sample code to the Declarations portion of a form. Make sure that the form contains:

  • A Label named Label1 and a TextBox named TextBox1.
  • A Label named Label2 and a TextBox named TextBox2.
  • A ScrollBar named ScrollBar1.
  • A Label named Label3.
    Dim TempNum As Integer
    
    Private Sub UserForm_Initialize()
        Label1.Caption = "Min -1000 to 1000"
        ScrollBar1.Min = -1000
        TextBox1.Text = ScrollBar1.Min
        TextBox1.MaxLength = 5
        
        Label2.Caption = "Max -1000 to 1000"
        ScrollBar1.Max = 1000
        TextBox2.Text = ScrollBar1.Max
        TextBox2.MaxLength = 5
        
        ScrollBar1.SmallChange = 1
        ScrollBar1.LargeChange = 100
        ScrollBar1.Value = 0
        Label3.Caption = ScrollBar1.Value
    End Sub
    
    Private Sub TextBox1_Change()
        If IsNumeric(TextBox1.Text) Then
            TempNum = CInt(TextBox1.Text)
            If TempNum >= -1000 And TempNum <= 1000 Then
                ScrollBar1.Min = TempNum
            Else
                TextBox1.Text = ScrollBar1.Min
            End If
        Else
            TextBox1.Text = ScrollBar1.Min
        End If
    End Sub
    
    Private Sub TextBox2_Change()
        If IsNumeric(TextBox2.Text) Then
            TempNum = CInt(TextBox2.Text)
            If TempNum >= -1000 And TempNum <= 1000 Then
                ScrollBar1.Max = TempNum
            Else
                TextBox2.Text = ScrollBar1.Max
            End If
        Else
            TextBox2.Text = ScrollBar1.Max
        End If
    End Sub
    
    Private Sub ScrollBar1_Change()
    Label3.Caption = ScrollBar1.Value
    End Sub