Results 1 to 4 of 4

Thread: Help with code

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,887
    Location
    Another way is to have 3 spin buttons and have the time displayed in a label or stored in a variable. That way there's no format issues or 'too large/small' problems

    Option Explicit
    Private Sub UserForm_Activate()
        With Me
            .sbHour = 0
            .sbMinute = 0
            .sbSecond = 0
        
            Call pvtUpdateTime
        End With
    End Sub
    
    Private Sub cbDone_Click()
        Dim dt As Date
        
        With Me
            .Hide
            dt = TimeSerial(.sbHour, .sbMinute, .sbSecond)
            Unload Me
        End With
        
        MsgBox "Time entered was " & Format(dt, "hh:mm:ss")
    End Sub
    Private Sub sbHour_Change()
        With Me.sbHour
            If .Value = .Max Then
                .Value = .Min
            ElseIf .Value = .Min Then
                .Value = .Max
            End If
            Call pvtUpdateTime
        End With
    End Sub
    Private Sub sbMinute_Change()
        With Me.sbMinute
            If .Value = .Max Then
                .Value = .Min
            ElseIf .Value = .Min Then
                .Value = .Max
            End If
            Call pvtUpdateTime
        End With
    End Sub
    Private Sub sbSecond_Change()
        With Me.sbSecond
            If .Value = .Max Then
                .Value = .Min
            ElseIf .Value = .Min Then
                .Value = .Max
            End If
            Call pvtUpdateTime
        End With
    End Sub
    
    Private Sub pvtUpdateTime()
        With Me
            .labTIme = Format(.sbHour, "00") & ":" & Format(.sbMinute, "00") & ":" & Format(.sbSecond, "00")
        End With
    End Sub
    Just another idea

    BTW, the attachment code is out of date, but I could not figure out how to replace it

    Paul
    Attached Files Attached Files
    Last edited by Paul_Hossler; 04-08-2014 at 08:55 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •