how to declare a button

T

Tony WONG

i write the following program to detect workstation ON or OFF

but i do not know how to paste the parameter from Timer1_Tick to pingwork

it comes to error in these lines -- WorkName
Private Sub pingwork(ByVal WorkIP, ByVal WorkName)
Dim WorkName As New Button

Could you teach me to do it? Thanks a lot.



************************************************
Public Class Form1

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
pingwork("Work01", "Work01")
pingwork("Work02", "Work02")
End Sub

Private Sub pingwork(ByVal WorkIP, ByVal WorkName)
Dim WorkName As New Button
Controls.Add(WorkName)
WorkName.Text = WorkIP

If My.Computer.Network.Ping(WorkIP) Then
WorkName.BackColor = Color.Gold
WorkName.ForeColor = Color.Black
Else
WorkName.BackColor = Color.Black
WorkName.ForeColor = Color.White
End If
WorkName.Refresh()
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Timer1.Interval = 5000
Timer1.Enabled = True
End Sub
End Class
 
K

kimiraikkonen

i write the following program to detect workstation ON or OFF

but i do not know how to paste the parameter from Timer1_Tick to pingwork

it comes to error in these lines -- WorkName
Private Sub pingwork(ByVal WorkIP, ByVal WorkName)
Dim WorkName As New Button

Could you teach me to do it? Thanks a lot.

************************************************
Public Class Form1

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
pingwork("Work01", "Work01")
pingwork("Work02", "Work02")
End Sub

Private Sub pingwork(ByVal WorkIP, ByVal WorkName)
Dim WorkName As New Button
Controls.Add(WorkName)
WorkName.Text = WorkIP

If My.Computer.Network.Ping(WorkIP) Then
WorkName.BackColor = Color.Gold
WorkName.ForeColor = Color.Black
Else
WorkName.BackColor = Color.Black
WorkName.ForeColor = Color.White
End If
WorkName.Refresh()
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Timer1.Interval = 5000
Timer1.Enabled = True
End Sub
End Class

Couldn't estimate what you exactly done but if declare new button
before you declare "pingwork" function sub. Also it would be more
helpful to paste error message. I simulated your code you get the
error:

"WorkName' is already declared as a parameter of this method." then
what you must do is to declare WorkName button just before "pingwork"
sub.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top