call New sub in this manner?

ssormanni

Member
Joined
Nov 12, 2010
Messages
5
Location
Italy
Programming Experience
Beginner
I works very well, but now I've a new question:
I read from the Slave every 10 sec. I want control if my slave is offline before reading. To do this I call New sub in this manner:

Dim IDEA as TcpClient
Dim Premium as Device.ModbusIpMaster
Public Sub new()
Try
IDEA = New TcpClient("192.168.1.101", 502)
Catch Errore As Exception
MsgBox("Can't connect PLC Socket")
Sleep(10000)
Call NEW()
End Try

.........

Timer1(...)
Call NEW
........
Timer2(...)
Call NEW

My question is: Create several time my TCPClient, Could be wrong?

Thanks a lot..

Stefano
 
Sub New is a special method called constructor, this is called only when an instance of the class is created using the New keyword. If you need to call a method repeatedly you have to define a regular Sub method, you can of course also call this from the constructor.
 
Back
Top