Why this code does not work properly? 
Author Message
 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 -



Tue, 17 May 2005 02:32:02 GMT  
 Why this code does not work properly?

Quote:
> 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...

Quote:
> THANK YOU IN ADVANCE TO ALL THE ONES THAT WILL DECIDE TO HELP ME!

OMG YOU'RE WELCOME!!!!!!!!!!!!!!!!!!!!!!!!


Tue, 17 May 2005 02:50:06 GMT  
 Why this code does not work properly?
That's all. *Why this code is not correct?*

Quote:
> 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



Sat, 21 May 2005 00:05:12 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Why does not then Keyboard handling work properly.....

2. Why does the following code not work?

3. this code does not work, why?

4. Help Please...Code does not work why?

5. Why code will not work?

6. Why does this piece of code work with Word 97 but not Word 2000

7. why will this code not work

8. Find/Replace code not working - why?

9. Why this code does not work:

10. why the @#$@% does this code not work

11. Anyone know why this code only works in 32bit and not 16 bit vb 4

12. Why does this code not work?

 

 
Powered by phpBB® Forum Software