Results 1 to 10 of 10

Thread: Almost there...

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    3
    ok, I used the code:

    Declare Function ExitWindowsEx Lib "user32.dll" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long

    Private Sub Timer1_Timer()
    Label1.Caption = Format(Time, "HH:MM:SS")
    If Text1.Text = Label1.Caption Then
    Call ExitWindowsEx(1, 0)
    End If
    End Sub

    the problem I am running into is that it what let me declare the function as public. If I declare it as private, it won't run. By the way, this code is to have VB automatically shut down windows at a certain time. Any info is appreciated.

  2. #2
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    You can't declare things Public in a form. Add a module to your project and declare it as public in the module.
    Oetje
    [email protected]
    93606776
    Visual Basic 6, Windows 2000

    Never pet a burning dog

  3. #3
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    It is not because of the Private/Public thing.
    You can make it Private and keep it in your form, or make it Public and move it to a module... Same thing.
    It is set to shut down Windows when Timer1_Timer occurs, and Text1.Text contains the same as Label1.Caption (which is set to the current time in HH:MM:SS form immediately before that).

    Are you sure all the above occurs?

  4. #4

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    3
    It still does nothing. I put the declaration in a module.

  5. #5
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    • Are you sure the Timer1 exists (and is a Timer)?
    • Are you sure Timer1.Enabled = True?
    • Are you sure Timer1.Interval isn't zero?
    • Are you sure Label1 exists (and is a Label)?
    • Are you sure Text1 exists (and is a TextBox)?
    • Are you sure that every N milliseconds (N = Timer1.Interval), Label1.Caption changes to the current time in HH:MM:SS form? (You can use a Debug.Print to make sure the event is reached)
    • Are you sure you typed that in Text1 exactly as it appears in Label1?
    And finally...
    • Are you sure all that code (except the Declare maybe) appears in the same form, and this form is the one that contains the Timer1, Label1 and Text1?

    After you have made sure that all these things are OK, it should work.

  6. #6

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    3
    Here is the code EXACTLY as it appears on the form:

    Private Sub Timer1_Timer()

    Timer1.Enabled = True
    Timer1.Interval = 1
    Label1.Caption = Format(Time, "HH:MM:SS")
    If Text1.Text = Label1.Caption Then
    Call ExitWindowsEx(1, 0)
    End If

    End Sub

    still doesn't work, there is obviously something that I am overlooking that is holding this up.

  7. #7
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    You need to put the lines:
    Code:
    Timer1.Enabled = True 
    Timer1.Interval = 1
    In the Form_Load event.
    Oetje
    [email protected]
    93606776
    Visual Basic 6, Windows 2000

    Never pet a burning dog

  8. #8
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    Or, in design mode, you can put 1 in the Interval property and True in the Enabled property.
    Either way, those two lines don't belong in Timer1_Timer.

  9. #9
    Hyperactive Member Asaf_99's Avatar
    Join Date
    Jul 2000
    Location
    Israel
    Posts
    335
    Originally posted by remiller1
    Here is the code EXACTLY as it appears on the form:

    Private Sub Timer1_Timer()

    Timer1.Enabled = True
    Timer1.Interval = 1
    Label1.Caption = Format(Time, "HH:MM:SS")
    If Text1.Text = Label1.Caption Then
    Call ExitWindowsEx(1, 0)
    End If

    End Sub

    still doesn't work, there is obviously something that I am overlooking that is holding this up.
    I don't feel like the If statement is good...
    If Text1.Text = Label1.Caption Then ???
    Does Text1 contain a time to shutdown windows?
    If so, try:
    If Label1.Caption = Text1.Text Then

    I think that is it...
    Asaf Sagi

    ICQ: 61917199
    E-Mail: [email protected]

  10. #10
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Asaf, I don't think that makes sense...

    so you say there's a difference between

    2 + 3 = 8 - 3
    and
    8 - 3 = 2 + 3

    I think they're pretty the same, they both turn out to be true.

    hmmm so it doesn't matter if you say
    Text1 = Label1
    or
    Label1 = Text1
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width