Skip to content

Slider Control (VBCCRSlider)

VBCCRSlider control is a slider control that allows users to select a value within a range by dragging a slider. It supports both horizontal and vertical orientations and provides various customization options.

Properties

Key Properties

  • Value: Current value
  • Min: Minimum value
  • Max: Maximum value
  • SmallChange: Small change amount (when using arrow keys)
  • LargeChange: Large change amount (when clicking the track)
  • Orientation: Orientation (horizontal or vertical)
  • TickStyle: Tick mark style
  • TickFrequency: Tick mark frequency
  • SelectRange: Whether range selection is allowed
  • SelStart: Selection range start value
  • SelLength: Selection range length
  • Enabled: Enable/disable control

Methods

Main Methods

  • Value = NewValue: Set current value
  • SetRange(Min As Long, Max As Long): Set value range
  • Refresh(): Refresh display

Events

  • Change(): Triggered when value changes
  • Scroll(): Triggered while scrolling
  • Click(): Triggered when clicked
  • MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  • MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  • KeyDown(KeyCode As Integer, Shift As Integer)
  • KeyUp(KeyCode As Integer, Shift As Integer)

Code Examples

Basic Usage

vb
Private Sub Form_Load()
    With Slider1
        .Min = 0
        .Max = 100
        .Value = 50
        .SmallChange = 1
        .LargeChange = 10
        .TickStyle = sldBottomRight
        .TickFrequency = 10
    End With
End Sub

Volume Control

vb
Private Sub CreateVolumeControl()
    With Slider1
        .Orientation = sldVertical
        .Min = 0
        .Max = 100
        .Value = 75
        .TickStyle = sldBoth
        .TickFrequency = 20
    End With
End Sub

Private Sub Slider1_Change()
    ' Update volume display
    lblVolume.Caption = "Volume: " & Slider1.Value & "%"
    
    ' Set system volume
    SetSystemVolume Slider1.Value
End Sub

Range Selection

vb
Private Sub SetupRangeSlider()
    With Slider1
        .SelectRange = True
        .Min = 0
        .Max = 1000
        .SelStart = 200
        .SelLength = 400
        .TickFrequency = 100
    End With
End Sub

Private Sub Slider1_Change()
    lblRange.Caption = "Selected Range: " & _
                      Slider1.SelStart & " - " & _
                      (Slider1.SelStart + Slider1.SelLength)
End Sub

Common Use Cases

Image Zoom Control

vb
Private Sub CreateZoomControl()
    ' Set up zoom slider
    With sldZoom
        .Min = 10 ' 10%
        .Max = 200 ' 200%
        .Value = 100 ' 100%
        .SmallChange = 5
        .LargeChange = 25
        .TickFrequency = 50
    End With
End Sub

Private Sub sldZoom_Change()
    Dim ZoomFactor As Single
    ZoomFactor = sldZoom.Value / 100
    
    ' Update image zoom
    picImage.Width = OriginalWidth * ZoomFactor
    picImage.Height = OriginalHeight * ZoomFactor
    
    ' Update zoom information
    lblZoom.Caption = sldZoom.Value & "%"
End Sub

Date Range Selector

vb
Private Sub CreateDateRangeSlider()
    Dim StartDate As Date
    Dim EndDate As Date
    
    StartDate = DateSerial(Year(Date), 1, 1)
    EndDate = DateSerial(Year(Date), 12, 31)
    
    With Slider1
        .Min = 0
        .Max = DateDiff("d", StartDate, EndDate)
        .SelectRange = True
        .SelStart = 0
        .SelLength = 30 ' Default select 30 days
        .TickFrequency = 30 ' Show tick marks monthly
    End With
End Sub

Private Sub UpdateDateRange()
    Dim StartDate As Date
    StartDate = DateSerial(Year(Date), 1, 1)
    
    lblDateRange.Caption = "Selected Range: " & _
        Format$(DateAdd("d", Slider1.SelStart, StartDate), "yyyy-mm-dd") & _
        " to " & _
        Format$(DateAdd("d", Slider1.SelStart + Slider1.SelLength, StartDate), "yyyy-mm-dd")
End Sub

Best Practices

  1. Value Validation
vb
Private Function ValidateValue(ByVal NewValue As Long) As Long
    ' Ensure value is within valid range
    If NewValue < Slider1.Min Then
        ValidateValue = Slider1.Min
    ElseIf NewValue > Slider1.Max Then
        ValidateValue = Slider1.Max
    Else
        ValidateValue = NewValue
    End If
End Function
  1. Error Handling
vb
Private Sub SafeUpdateValue(ByVal NewValue As Long)
    On Error GoTo ErrorHandler
    
    Slider1.Value = ValidateValue(NewValue)
    Exit Sub
    
ErrorHandler:
    Debug.Print "Slider update error: " & Err.Description
End Sub

Known Issues and Solutions

  1. Update Issues
vb
Private Sub FixUpdateIssues()
    Static IsUpdating As Boolean
    
    If IsUpdating Then Exit Sub
    IsUpdating = True
    
    ' Perform updates here
    UpdateLinkedControls
    
    IsUpdating = False
End Sub
  1. Refresh Issues
vb
Private Sub HandleRefreshIssues()
    ' Force redraw if needed
    Slider1.Visible = False
    Slider1.Visible = True
End Sub

Additional Tips

  1. Synchronized Controls
vb
Private Sub SyncControls()
    ' Update linked textbox
    txtValue.Text = Slider1.Value
    
    ' Update linked progress bar
    ProgressBar1.Value = Slider1.Value
End Sub
  1. Custom Formatting
vb
Private Sub FormatSliderDisplay()
    ' Format value display
    Select Case DisplayMode
        Case "Percentage"
            lblValue.Caption = Slider1.Value & "%"
        Case "Currency"
            lblValue.Caption = Format$(Slider1.Value, "Currency")
        Case "Temperature"
            lblValue.Caption = Slider1.Value & "°C"
    End Select
End Sub
  1. Keyboard Navigation
vb
Private Sub Slider1_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
        Case vbKeyHome
            Slider1.Value = Slider1.Min
        Case vbKeyEnd
            Slider1.Value = Slider1.Max
        Case vbKeyPageUp
            Slider1.Value = Slider1.Value + Slider1.LargeChange
        Case vbKeyPageDown
            Slider1.Value = Slider1.Value - Slider1.LargeChange
    End Select
End Sub

Performance Optimization

  1. Batch Updates
vb
Private Sub BatchUpdate()
    Dim i As Long
    
    Screen.MousePointer = vbHourglass
    Form1.AutoRedraw = False
    
    For i = Slider1.Min To Slider1.Max Step 10
        Slider1.Value = i
        ' Process updates in batches
        If i Mod 50 = 0 Then
            DoEvents
            UpdateDisplay
        End If
    Next i
    
    Form1.AutoRedraw = True
    Screen.MousePointer = vbDefault
End Sub
  1. Event Handling Optimization
vb
Private Sub OptimizedEventHandling()
    Static LastUpdate As Single
    
    ' Limit update frequency
    If Timer - LastUpdate < 0.1 Then Exit Sub
    
    UpdateDisplay
    LastUpdate = Timer
End Sub

VB6 and LOGO copyright of Microsoft Corporation