Working with shell and timers in Visual Basic? [HELP]

Discussion in 'Computing, Science, and Technology' started by JIMIneitor, Sep 20, 2009.

  1. JIMIneitor

    JIMIneitor Banned

    Joined:
    Feb 21, 2009
    Messages:
    1,125
    Likes Received:
    5
    Device:
    4G iPod touch
    Hi there, again!

    Im trying to make a simple app in Visual Basic that can shutdown your PC either inmediately or in a certain amount of time.

    I have two forms, the main one has two buttons, one turns of the PC inmediately and the other opens the second form.

    That form has two labels, one textbox, and one button

    The labels are just informative, the textbox is where you type the time you want, and the button, well it starts the countdown.

    The problem is that i dont know the exact syntaxis to accomplish this.
    Inmediate shutdown works, but the second button doesnt.

    I have this code for the main form (the one that works)

    Code:
    Public Class frmMainShutdown
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShutdownNow.Click
            Shell("shutdown -s")
            Me.Close()
        End Sub
    
        Private Sub btnShutdownTime_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShutdownTime.Click
            frmTime.ShowDialog()
    
        End Sub
    End Class
    And this for the second one (the one that im having problems with)

    Code:
    Public Class frmTime
    
        Private Sub txtTime_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtTime.TextChanged
    
        End Sub
    
        Private Sub btnShutdown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShutdown.Click
            Dim strShutdownTime As String
            Dim intShutdownTime As Integer
            strShutdownTime = txtTime.Text
            intShutdownTime = txtTime.Text
            Shell("shutdown -s -t & strShutdownTime & ")
            tmrToShutdown.Interval = intShutdownTime
    
    
    
    
        End Sub
    
        Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblToShutdown.Click
            Me.Text = ""
        End Sub
    End Class
    Also, i want to have a timer that starts counting when the user clicks the button, but ive no idea on how to work with timers, soo please, haalp!

    KTHXBAI
  2. Tarthen

    Tarthen New Member

    Joined:
    Sep 3, 2009
    Messages:
    77
    Likes Received:
    0
    Device:
    iPod touch
    Make a timer on the shutdown later form. Then do this:

    Code:
    Private Sub btnShutdown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShutdown.Click
    
    Dim intShutdownTime as integer
    intShutdownTime = Integer.Parse(txtTime.text)
    Timer1.Interval = intShutdownTime
    Timer1.Enabled = True
    
    End Sub
    
    Private Sub Timer1_Tick
    
    Shell("shutdown -s")
    
    End Sub
    This might not work quite right. You may need to tinker with the sub names. But that's how I'd do it.

Share This Page