Wrox Programmer Forums
|
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 20th, 2006, 09:44 AM
Registered User
 
Join Date: Dec 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Call a Sub or Command

Right i have a form with two button a text box and a few labels. Button one when clicked pings a computer and displays the resault in the text box. Button two when clicked send a telnet command and reboots my server.

These are working fine. But i have now added a count down timer to the form (5mins). What i want to happen is when the timer gets down to 0 i want it to run the ping. So will i need to type out the ping command again in the timer_tick section or can i place this:-
Code:
Private Sub btnPing_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPing.Click


        If My.Computer.Network.Ping("10.50.50.217") Then
            lblDisplay.Text = "Server pinged successfully."
            Count = 0
            lblcount.Text = Count

        Else
            lblDisplay.Text = "Ping request timed out."
            Count = Count + 1
            lblcount.Text = Count

        End If

    End Sub

into a command/procedure and then call it from the button click and when the timer gets to zero.

e.g.
Code:
Private Sub btnPing_Click

call [ping_command]

end sub

and

Private Sub Timer_tick

If Counter = 0 then call [ping_command]

end sub
Or what ever the command(s) would be?
 
Old December 20th, 2006, 09:46 AM
Registered User
 
Join Date: Dec 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

for your information here is the complete VB code i have so far

Code:
Public Class Form1

    Dim Count As Integer
    Dim Counter As Integer

    Private WithEvents w3sock As Socket.TCP
    Private Sub Form1_Laod(ByVal sender As System.Object, ByVal ByVal_e As System.EventArgs) Handles MyBase.Load
        w3sock = New Socket.TCP

        Timer1.Enabled = True

    End Sub


    Private Sub btnRestart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRestart.Click
        On Error GoTo ErrorHandler

        w3sock.TimeOut = 5000
        w3sock.DoTelnetEmulation = True
        w3sock.TelnetEmulation = "TTY"
        w3sock.Host = "10.50.50.253:23"
        w3sock.Open()

        w3sock.WaitFor("login:")
        w3sock.SendLine("netscreen")
        w3sock.WaitFor("password:")
        w3sock.SendLine("surestore")
        w3sock.WaitFor("> ")
        w3sock.SendLine("reset")
        w3sock.WaitFor("[n] ")
        w3sock.SendLine("y")
        w3sock.WaitFor("In Reset")
        w3sock.Close()

        Exit Sub

ErrorHandler:
        MsgBox(Err.Description, MsgBoxStyle.Critical, "Error Detected")
        Err.Clear()
        w3sock.Close()
    End Sub

    Private Sub btnPing_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPing.Click


        If My.Computer.Network.Ping("10.50.50.217") Then
            lblDisplay.Text = "Server pinged successfully."
            Count = 0
            lblcount.Text = Count

        Else
            lblDisplay.Text = "Ping request timed out."
            Count = Count + 1
            lblcount.Text = Count

        End If

    End Sub



    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        If Counter = 0 Then
            Counter = 300

        Else
            Counter = Counter - 1
        End If
        lbltimer.Text = Counter

    End Sub


End Class
 
Old December 21st, 2006, 11:22 AM
Registered User
 
Join Date: Dec 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Found the solution nice and simple






Similar Threads
Thread Thread Starter Forum Replies Last Post
Command text was not set for the command object Sheraz Khan Classic ASP Databases 2 May 29th, 2007 12:57 AM
How to call QBasic command in VB.Net kiwibey Visual Studio 2005 1 January 10th, 2007 11:37 AM
How to call a sub in a sub busybee ASP.NET 1.0 and 1.1 Basics 4 March 22nd, 2006 01:39 AM
Command text was not set for the command object. deepa12 BOOK: Beginning ASP 3.0 5 November 2nd, 2004 05:37 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.