Question manage Exception into the Form (VB 2008)

ssormanni

Member
Joined
Nov 12, 2010
Messages
5
Location
Italy
Programming Experience
Beginner
Hi all,
I've a little problem to how manage a TCP client exception. I've declared a client in Form1 as described below:

Public Class Form1
'
Public IDEA As New TcpClient("192.168.1.21", 502)
Public Premium As Device.ModbusIpMaster = Modbus.Device.ModbusIpMaster.CreateIp(IDEA)


I want to manage the Exception (ie when my client is offline) by Try..Catch, but unfortunally inside Form1 I can't.
How can I bypass this problem?

Thanks a lot who reply to me

Stefano
 
ssormanni said:
Public IDEA As New TcpClient("192.168.1.21", 502)
this is short for (declaring variable, creating object and assign reference to variable):
VB.NET:
Public IDEA As TcpClient = New TcpClient("192.168.1.21", 502)
And this is really just a convenience for you as VB developer, when application is compiled this is rearranged to something like this:
VB.NET:
Public IDEA As TcpClient 

Public Sub New()
    IDEA = New TcpClient("192.168.1.21", 502)
End Sub
Can you see where this is getting at? You can do something similar, and add the Try-Catch now.
 
Hi John, and thank you very much for your fast reply. This is a Slave Modbus and I have to manage the error in case of my system has a Shutdown. I will try soon your Adjustment.

Cheers
 
Back
Top