Results 1 to 3 of 3

Thread: Date function issue [RESOLVED]

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    248

    Resolved Date function issue [RESOLVED]

    Hi all,

    As you might remember I posted a post a couple of days back regarding Timers.

    The application that I'm making is a program that will restart the computer after a certain period of time. This can be done in one of two ways: Either when the coundown reaches 0, or when the clock reaches a specified time:



    As you can see, on the right are hour/minute/second fields. When filled in and "Set" is activated, it will count down and when it gets to 0, restart the computer. This is working fine (You will notice in the source there is no restart code; I'm leaving that until right at the end. Currently it just gives a msgbox).

    The problem that I now have is the right hand section: making it shut down at a certain date. With the countdown it was easy; just multiply the hour and minute boxes by 3600 and 60 respectively, and add all 3 together (to get the total in seconds) and just make the timer look to that variable.

    The problem here is that I have 3 text boxes (on the right), dropping their entried into 3 "Date" type variables. I now need to somehow make those add together and generate a 24 hour time. That will then be stored, and when the system clock reaches the same as the stored 24hour "Time", activate the code.

    HERE is a complete ZIP of the whole project. Below you can also see the whole source code used for the program. Here's an extract of my comments around the area that i'm discussing:

    Code:
        ' I need a way to turn those 3 vars (NOT the I ones. the I ones are
        ' Just there to allow me to post the shutdown time to TSD)
        ' into a time on the 24 hour scale.
        ' From this I will calculate how long left until it reaches that time
        ' And set that information to "Time remaining until shutdown"
    And here's the section of code itself:

    Code:
        NewHour = TimeH
        NewMin = TimeM
        NewSec = TimeS
        NewHouri = TimeH
        NewMini = TimeM
        NewSeci = TimeS
    
        ' I need a way to turn those 3 vars (NOT the I ones. the I ones are
        ' Just there to allow me to post the shutdown time to TSD)
        ' into a time on the 24 hour scale.
        ' From this I will calculate how long left until it reaches that time
        ' And set that information to "Time remaining until shutdown"
    
        TotalTime = NewHour + NewMin + NewSec
    
        TSD = NewHouri & ":" & NewMini & ":" & NewSeci
    Everything else within that part of the IF statement is the same as it is for the left section.

    Anyone know how I might do this?

    Thanks








    Code:
    Option Explicit
    ' ShutTimer © ArbitalSystems 2005
    ' Created on the 12/09/05
    
    Dim AddMins As Date
    Dim AddHours As Date
    Dim TotalTime As Date
    Dim OldTime As Date
    Dim newTime As Date
    Dim diff As Long
    Dim SetUnset As Boolean
    
    Private Declare Function DeleteMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
    Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As Long, ByVal bRevert As Long) As Long
    Private Const MF_BYPOSITION = &H400&
    
    Private Sub About_Click()
    MsgBox "ShutTimer Auto-shutdown application © ArbitalSystems 2005. All rights reserved.", vbInformation, "About"
    End Sub
    
    
    Private Sub CdownTimer_Timer()
    
    newTime = Time
    diff = DateDiff("s", newTime, OldTime)
    TTSD.Caption = (diff \ 60) & ":" & _
            Format((diff - ((diff \ 60) * 60)), "00")
            
    If diff = 0 Then
        CdownTimer.Enabled = False
        TTSD.Caption = ""
        TSD.Caption = ""
        UTi.Enabled = True
        UCi.Enabled = True
        About.Enabled = True
        SetTimer.Caption = "Set"
        SetUnset = False
        
        ' Your time is UP!  Do something!
    
        Beep
        MsgBox "Computer shuts down"
    
    End If
    
    
    
    
    
    
    End Sub
    
    Private Sub Exiti_Click()
    End
    End Sub
    
    Private Sub Explain_Click()
    Abouti.Visible = True
    End Sub
    
    Private Sub Form_Load()
    
    UTi.Value = True
    RemoveMenus
    SetUnset = False
    
    End Sub
    
    Private Sub SetTimer_Click()
    Dim NewHour As Date
    Dim NewMin As Date
    Dim NewSec As Date
    Dim NewHouri As String
    Dim NewMini As String
    Dim NewSeci As String
    
    If SetUnset = True Then
        CdownTimer.Enabled = False
        TTSD.Caption = ""
        TSD.Caption = ""
        UTi.Enabled = True
        UCi.Enabled = True
        About.Enabled = True
        SetTimer.Caption = "Set"
        SetUnset = False
        Exit Sub
    End If
    
    If UTi = True Then
        If Hrs = "" Or Mins = "" Or Secs = "" Then
            MsgBox "Please enter a value in all 3 boxes. If you don't want to use a box, enter a '0' in it.", , "Incorrect input"
            Exit Sub
        End If
        
        If Hrs > "500" Then
            MsgBox "Please enter 500 or less for hours.", , "Error in input"
            Exit Sub
        End If
        
        
        NewHour = Hrs
        NewMin = Mins
        NewSec = Secs
        AddMins = NewMin * 60
        AddHours = NewHour * 3600
        TotalTime = NewSec + AddMins + AddHours
        OldTime = DateAdd("s", TotalTime, Time)
        CdownTimer.Enabled = True
        
        UTi.Enabled = False
        UCi.Enabled = False
        About.Enabled = False
        SetTimer.Caption = "Stop"
        SetUnset = True
    '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    ElseIf UCi = True Then
    '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
        If Hrs = "" Or Mins = "" Or Secs = "" Then
            MsgBox "Please enter a value in all 3 boxes. If you don't want to use a box, enter a '0' in it.", , "Incorrect input"
            Exit Sub
        End If
        
        If Hrs > "500" Then
            MsgBox "Please enter 500 or less for hours.", , "Error in input"
            Exit Sub
        End If
        
        NewHour = TimeH
        NewMin = TimeM
        NewSec = TimeS
        NewHouri = TimeH
        NewMini = TimeM
        NewSeci = TimeS
    
        ' I need a way to turn those 3 vars (NOT the I ones. the I ones are
        ' Just there to allow me to post the shutdown time to TSD)
        ' into a time on the 24 hour scale.
        ' From this I will calculate how long left until it reaches that time
        ' And set that information to "Time remaining until shutdown"
    
        TotalTime = NewHour + NewMin + NewSec
    
        TSD = NewHouri & ":" & NewMini & ":" & NewSeci
        
        
        
        UTi.Enabled = False
        UCi.Enabled = False
        About.Enabled = False
        SetTimer.Caption = "Stop"
        SetUnset = True
        
    Else
        MsgBox "Please select an option!", , "Select option"
        Exit Sub
    End If
    
    End Sub
    
    Private Sub UCi_Click()
    
    SetTimer.Enabled = True
    TimeH.Enabled = True
    TimeM.Enabled = True
    TimeS.Enabled = True
    
    Hrs.Enabled = False
    Mins.Enabled = False
    Secs.Enabled = False
    
    Hrs.Text = "0"
    Mins.Text = "0"
    Secs.Text = "0"
    
    End Sub
    
    Private Sub UTi_Click()
    
    SetTimer.Enabled = True
    Hrs.Enabled = True
    Mins.Enabled = True
    Secs.Enabled = True
    
    TimeH.Enabled = False
    TimeM.Enabled = False
    TimeS.Enabled = False
    
    TimeH.Text = "0"
    TimeM.Text = "0"
    TimeS.Text = "0"
    
    End Sub
    
    
    Private Sub Hrs_KeyPress(KeyAscii As Integer)
    If (KeyAscii = 8) Or (KeyAscii = 9) Then Exit Sub
    If (KeyAscii < 48) Or (KeyAscii > 57) Then
        KeyAscii = 0
        MsgBox "Please input Numbers only"
    End If
    End Sub
    
    Private Sub Mins_KeyPress(KeyAscii As Integer)
    If (KeyAscii = 8) Or (KeyAscii = 9) Then Exit Sub
    If (KeyAscii < 48) Or (KeyAscii > 57) Then
        KeyAscii = 0
        MsgBox "Please input Numbers only"
    End If
    End Sub
    
    Private Sub ResetTime_Timer()
    RTime.Caption = Time
    End Sub
    
    Private Sub Secs_KeyPress(KeyAscii As Integer)
    If (KeyAscii = 8) Or (KeyAscii = 9) Then Exit Sub
    If (KeyAscii < 48) Or (KeyAscii > 57) Then
        KeyAscii = 0
        MsgBox "Please input Numbers only"
    End If
    End Sub
    
    Private Sub TimeH_KeyPress(KeyAscii As Integer)
    If (KeyAscii = 8) Or (KeyAscii = 9) Then Exit Sub
    If (KeyAscii < 48) Or (KeyAscii > 57) Then
        KeyAscii = 0
        MsgBox "Please input Numbers only"
    End If
    End Sub
    
    Private Sub TimeM_KeyPress(KeyAscii As Integer)
    If (KeyAscii = 8) Or (KeyAscii = 9) Then Exit Sub
    If (KeyAscii < 48) Or (KeyAscii > 57) Then
        KeyAscii = 0
        MsgBox "Please input Numbers only"
    End If
    End Sub
    
    Private Sub TimeS_KeyPress(KeyAscii As Integer)
    If (KeyAscii = 8) Or (KeyAscii = 9) Then Exit Sub
    If (KeyAscii < 48) Or (KeyAscii > 57) Then
        KeyAscii = 0
        MsgBox "Please input Numbers only"
    End If
    End Sub
    
    
    Private Sub RemoveMenus()
    Dim hMenu As Long
        ' Get the form's system menu handle.
        hMenu = GetSystemMenu(hWnd, False)
        DeleteMenu hMenu, 6, MF_BYPOSITION
    End Sub
    Last edited by Hack; Sep 13th, 2005 at 06:23 AM.

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Date function issue

    I've been working on this for a few minutes. I might finish it off and put it in the CodeBank!

    If you don't change the minutes, it adds 30 seconds to the alarm time. When it fires, a messagebox appears.
    Attached Files Attached Files

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    248

    Re: Date function issue

    Ah! That looks like just the thing. Thank you!

Posting Permissions

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



Click Here to Expand Forum to Full Width