?
Solved

Visual Basic time problem

Posted on 2003-03-04
4
Medium Priority
?
168 Views
Last Modified: 2013-11-25
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
Comment
Question by:macgyver2003
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 5

Expert Comment

by:JohnMcCann
ID: 8069355
Have you tried the DTPicker in Microsoft Windows Common Controls 2 - 6.0
0
 
LVL 11

Accepted Solution

by:
supunr earned 150 total points
ID: 8069389
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
 
LVL 11

Expert Comment

by:supunr
ID: 8069417
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
 

Author Comment

by:macgyver2003
ID: 8076663
got it. used timeserial(H,M,S), and compared it to hour(time) and minute(time). works perfect. thanks
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question