Option Explicit
Public Spegnimento As Boolean
Public Differenza As Integer
Public Data As String
Public Ora As String
Public Ore As Integer
Public Min As Integer
Public Sec As Integer
Private Function Differenza_Ore(Ore As Integer, Min As Integer, Sec As Integer)
Sec = Sec - Second(Time)
If Sec < 0 And Min > 0 Then
Sec = Sec + 60
Min = Min - 1
End If
Min = Min - Minute(Time)
If Min < 0 And Ore > 0 Then
Min = Min + 60
Ore = Ore - 1
End If
Ore = Ore - Hour(Time)
Differenza_Ore = Ore & "." & Min & "." & Sec
End Function
Private Sub Controllo(Oggetto As TextBox, LimiteInferiore As Integer, LimiteSuperiore As Integer)
If IsNumeric(Oggetto) = False Then GoTo NumerO
If Oggetto > LimiteSuperiore Or Oggetto < LimiteInferiore Then GoTo SbagliatO
Exit Sub
NumerO:
MsgBox "Errore, inserisci un valore numerico", vbCritical
Form_Load
Exit Sub
SbagliatO:
MsgBox "Inserisci un numero maggiore o uguale a " & LimiteInferiore & " e minore o uguale a " & LimiteSuperiore, vbExclamation
Form_Load
End Sub
Private Sub chkAbilita_Click()
cmdAdesso.Enabled = CBool(chkAbilita)
End Sub
Private Sub cmdAdesso_Click()
Tempo.Enabled = False
Shutdown EWX_POWEROFF
Unload Me
End
End Sub
Private Sub cmdAttiva_Click()
Dim I As Integer
Data = txtTime(0) & "/" & txtTime(1) & "/" & txtTime(2)
If IsDate(Data) = False Then
MsgBox "Errore, data inserita non valida", vbExclamation
Form_Load
End If
Data = txtTime(0) & "/" & txtTime(1) & "/" & txtTime(2)
Differenza = Abs(DateDiff("d", Data, Date))
If Differenza = 0 And Data <= Date Then GoTo Data_Grande
If Differenza > 0 Then
Controllo txtTime(3), 0, 23
Controllo txtTime(4), 0, 59
Controllo txtTime(5), 0, 59
End If
Ora = txtTime(3) & "." & txtTime(4) & "." & txtTime(5)
If Date <= Data Or Ora > Time Then
Tempo.Enabled = True
cmdStop_Avvia.Enabled = True
Spegnimento = True
For I = 0 To 5
txtTime(I).Enabled = False
Next I
End If
Exit Sub
Data_Grande:
MsgBox "Errore, inserire un orario valido", vbExclamation
Form_Load
End Sub
Private Sub cmdReset_Click()
Dim Risposta As VbMsgBoxResult
If Spegnimento = True Then Risposta = MsgBox("Sicuro di voler annullare il countdown?", vbQuestion + vbYesNo)
If Risposta = vbYes Or Spegnimento = False Then Form_Load
End Sub
Private Sub cmdStop_Avvia_Click()
Tempo.Enabled = Not Tempo.Enabled
If Tempo.Enabled = False Then cmdStop_Avvia.Caption = "A&vvia"
If Tempo.Enabled = True Then cmdStop_Avvia.Caption = "Sto&p"
If Spegnimento = False Then End
End Sub
Private Sub cmdEsci_Click()
Dim Risposta As VbMsgBoxResult
If Tempo.Enabled = True Then Risposta = MsgBox("Sicuro di voler terminare il processo?", vbQuestion + vbYesNo)
If Risposta = vbYes Or Tempo.Enabled = False Then End
End Sub
Private Sub Form_Load()
Dim I As Integer
Control_windows
For I = 0 To 5
txtTime(I).Enabled = True
Next I
cmdAttiva.Caption = "&Spegni pc all' ora stabilita"
cmdStop_Avvia.Enabled = False
cmdStop_Avvia.Caption = "Sto&p"
Tempo.Enabled = False
Spegnimento = False
txtTime(0) = Day(Date)
txtTime(1) = Month(Date)
txtTime(2) = Year(Date)
txtTime(3) = 23
txtTime(4) = 59
txtTime(5) = 59
chkAbilita_Click
End Sub
Private Sub Form_Unload(Cancel As Integer)
Cancel = 1
End Sub
Private Sub Tempo_Timer()
Dim DifferenzaORE As String
DifferenzaORE = Differenza_Ore(txtTime(3) + Differenza * 24, txtTime(4), txtTime(5))
cmdAttiva.Caption = "Tempo rimanente: " & vbCrLf & vbCrLf & DifferenzaORE
If DifferenzaORE = "0.0.0" Then cmdAdesso_Click
End Sub
Private Sub txtTime_GotFocus(Index As Integer)
txtTime(Index).SelStart = 0
txtTime(Index).SelLength = Len(txtTime(Index))
txtTime(Index).SetFocus
End Sub