Thread View: comp.lang.basic.visual.misc
3 messages
3 total messages
Started by Mirco Soderi
Thu, 28 Nov 2002 18:32
Why this code does not work properly?
Author: Mirco Soderi
Date: Thu, 28 Nov 2002 18:32
Date: Thu, 28 Nov 2002 18:32
64 lines
3365 bytes
3365 bytes
*************************************************************
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 -
Re: Why this code does not work properly?
Author: Doug Ross
Date: Thu, 28 Nov 2002 18:50
Date: Thu, 28 Nov 2002 18:50
12 lines
1797 bytes
1797 bytes
"Mirco Soderi" <mircosoderi@virgilio.it> wrote in message news:CitF9.4457$fa.162981@news1.tin.it... > Const EWX_SHUTDOWN = 1 const EWX_SHUTDOWN as long = 1& if it reboots or doesn't shutdown, you're outta luck here. this shutdown business is never consistent across machines... > THANK YOU IN ADVANCE TO ALL THE ONES THAT WILL DECIDE TO HELP ME! OMG YOU'RE WELCOME!!!!!!!!!!!!!!!!!!!!!!!!
Re: Why this code does not work properly?
Author: Arild Bakken
Date: Mon, 02 Dec 2002 16:05
Date: Mon, 02 Dec 2002 16:05
23 lines
2285 bytes
2285 bytes
Mirco Soderi wrote: 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 - For Windows 2000 and greater you need the SE_SHUTDOWN_NAME privilege on the process token. Read the documentation, on the ExitWindowsEx method on MSDN, it has sample code on how to aquire this privilege. Arild
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads