
Why this code does not work properly?
*************************************************************
The following is the content of my Form1 module that includes some
declarations
out of subroutine and just two subroutines.
*************************************************************
*** At module level, not included in any subroutine, I have the following:
***
Dim minuti As Integer
Dim secondi As Integer
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long,
ByVal dwReserved As Long) As Long
*** The following is a subroutine that enables a Timer to work after having
pushed on Button1 placed on Form1, and set minuti equal to the content of
text1 textbox... ***
Private Sub Command1_Click()
minuti = Text1.Text
Timer1.Enabled = True
End Sub
*** ... and this is the timer that does a count-down and *should* turn off
the PC after having completed the count-down (minuti < 0) ***
Private Sub Timer1_Timer()
If secondi = 0 Then
minuti = minuti - 1
secondi = 59
Else
secondi = secondi - 1
End If
Text1.Text = minuti & "." & secondi
If minuti < 0 Then
' *** THIS IS THE CODE THAT *SHOULD* TURN OFF PC ***
Const EWX_SHUTDOWN = 1
Dim ResLon As Long
ResLon = ExitWindowsEx(EWX_SHUTDOWN, 0&)
' *** END TURN OFF CODE ***
End If
End Sub
---------------------------------------------
That's all. *Why this code is not correct?*
Important info:
1. This is the only code of this very simple program. In effect, this
program is composed by a module (the
Form1 one) and the code included in this module is the one given above and
nothing more;
2. I have tried to use this program on a Windows XP Home Edition operating
system and the problem is that the count-down is ok but when it arrives to
zero, it goes to -1 minuti and 59 secondi and *the computer is not turned
off*.
THANK YOU IN ADVANCE TO ALL THE ONES THAT WILL DECIDE TO HELP ME!
- Mirco Soderi -