Help, I Dont know whats wrong!

Acer / Aspire t120c
April 27, 2009 at 19:13:51
Specs: Microsoft Windows XP Home Edition, 2.002 GHz / 735 MB
I am new to VBS however that dosn't stop me from making programs for people that need them, unfortuneatley the internet cant explain everything.
My most current program isn't working the way it should be.
It is for my libraian and should automatically logoff students at a certain time with a one minute warning...
Can some one please explain to me why it dosnt work and how to make it work.
It dosn't log off at the specified time.

code:

Private Sub Form_Load()
Form1.Visible = False
Dim x, WshShell, a, b, z
z = 0
x = (FormatDateTime(Now(), vbLongTime))
Do Until z = 1
If (x > "10:55:00 AM" And x < "10:57:00 AM") Then
z = 1
End If
If (x > "01:00:00 PM" And x < "01:02:00 PM") Then
z = 1
End If
If (x > "01:21:00 PM" And x < "01:23:00 PM") Then
z = 1
End If
Loop
a = MsgBox("You will be logged off in 1 minute so please start saving your work!", vbCritical, "Automatic Logoff")
WScript.sleep 50000
b = MsgBox("You will be logged off in 10 seconds!", vbCritical, "Automatic Logoff")
WScript.sleep 10000
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.run "shutdown /L /F"
End Sub

code:


See More: Help, I Dont know whats wrong!

Report •


#1
April 29, 2009 at 21:05:19
Private Sub Form_Load()
How is this function being called? VBScript doesn't have forms.

  Do Until z = 1
    If (x > "10:55:00 AM" And x < "10:57:00 AM") Then
      z = 1
    End If
    If (x > "01:00:00 PM" And x < "01:02:00 PM") Then
      z = 1
    End If
    If (x > "01:21:00 PM" And x < "01:23:00 PM") Then
      z = 1
    End If
  Loop
You're doing text comparisons for time. This forces a string comparison, not a date comparison. This is slower and more error prone. Don't.
You're looping endlessly without sleeping. This kills CPU. Don't.
You keep checking the value of x, but never change the value of x.

WScript.sleep 50000
If you're not going though Windows Script Host, you don't have access to WScript.Sleep.

Report •
Related Solutions


Ask Question