Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 169
  • Last Modified:

Visual Basic time problem

i am trying to make an interface with an on time and off time, that can be incremented by using up and down buttons for setting the times (hours and minutes), tried to get buddys/autobuddys to work but no luck yet.
any ideas. thanks....
0
macgyver2003
Asked:
macgyver2003
  • 2
1 Solution
 
JohnMcCannCommented:
Have you tried the DTPicker in Microsoft Windows Common Controls 2 - 6.0
0
 
supunrCommented:
OK here is my suggestion.

Have two text boxes next to each other txtHours and txtMinutes.
Add one UpDownTime (UpDown control) next to txtMin.

so in order to increament or decrement txtHours or txtMinutes, user first have to click inside a textbox
and then press updown arrow.  Below is the code.

Private HoursFocused As Boolean

Private Sub txtHours_GotFocus()
    HoursFocused = True
End Sub

Private Sub txtMinutes_GotFocus()
    HoursFocused = False
End Sub

Private Sub UpDownTime_DownClick()
    Dim HoursVal As Long
    Dim MinutesVal As Long
   
    If (HoursFocused) Then
        HoursVal = Val(txtHours.Text)
        HoursVal = HoursVal + 1
        If (HoursVal > 23) Then HoursVal = 0
        txtHours.Text = Right("00" & HoursVal, 2)
    Else
        MinutesVal = Val(txtMinutes.Text)
        MinutesVal = MinutesVal + 1
        If (MinutesVal > 59) Then MinutesVal = 0
        txtMinutes.Text = Right("00" & MinutesVal, 2)
    End If
End Sub

Private Sub UpDownTime_UpClick()
    Dim HoursVal As Long
    Dim MinutesVal As Long
   
    If (HoursFocused) Then
        HoursVal = Val(txtHours.Text)
        HoursVal = HoursVal - 1
        If (HoursVal < 0) Then HoursVal = 23
        txtHours.Text = Right("00" & HoursVal, 2)
    Else
        MinutesVal = Val(txtMinutes.Text)
        MinutesVal = MinutesVal - 1
        If (MinutesVal < 0) Then MinutesVal = 59
        txtMinutes.Text = Right("00" & MinutesVal, 2)
    End If
End Sub


Good Luck!!!
0
 
supunrCommented:
OK here is my suggestion.

Have two text boxes next to each other txtHours and txtMinutes.
Add one UpDownTime (UpDown control) next to txtMin.

so in order to increament or decrement txtHours or txtMinutes, user first have to click inside a textbox
and then press updown arrow.  Below is the code.

Private HoursFocused As Boolean

Private Sub txtHours_GotFocus()
    HoursFocused = True
End Sub

Private Sub txtMinutes_GotFocus()
    HoursFocused = False
End Sub

Private Sub UpDownTime_DownClick()
    Dim HoursVal As Long
    Dim MinutesVal As Long
   
    If (HoursFocused) Then
        HoursVal = Val(txtHours.Text)
        HoursVal = HoursVal + 1
        If (HoursVal > 23) Then HoursVal = 0
        txtHours.Text = Right("00" & HoursVal, 2)
    Else
        MinutesVal = Val(txtMinutes.Text)
        MinutesVal = MinutesVal + 1
        If (MinutesVal > 59) Then MinutesVal = 0
        txtMinutes.Text = Right("00" & MinutesVal, 2)
    End If
End Sub

Private Sub UpDownTime_UpClick()
    Dim HoursVal As Long
    Dim MinutesVal As Long
   
    If (HoursFocused) Then
        HoursVal = Val(txtHours.Text)
        HoursVal = HoursVal - 1
        If (HoursVal < 0) Then HoursVal = 23
        txtHours.Text = Right("00" & HoursVal, 2)
    Else
        MinutesVal = Val(txtMinutes.Text)
        MinutesVal = MinutesVal - 1
        If (MinutesVal < 0) Then MinutesVal = 59
        txtMinutes.Text = Right("00" & MinutesVal, 2)
    End If
End Sub


Good Luck!!!
0
 
macgyver2003Author Commented:
got it. used timeserial(H,M,S), and compared it to hour(time) and minute(time). works perfect. thanks
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now