>If put some of my code in a try/Catch to prevent a connection error, but when I do that, it's telling me that the loConnect object is not defined. I understand it is being smart and that if the try fails, the object would not be created, but it makes the program is it won't run. How is the best way to overcome this.
>
>Thanks
It is a scope issue. You have to make sure the loConnect is available outside of the Try catch. I'm not sure of the code in VB.NET, but you just need to declare the loConnect before the try connect.
Something like Dim loConnect as SqlConnect, or whatever type of object it is.
Do that before the try, and then leave the rest of the code the same, and it should be fine.
Hope that helps.
Morgan
>
> ' Create a Connection Object
> Dim loFactory = CreateObject("S2TCPComms.TCPConnectionFactory")
> ' Connect to Remote Site
> Try
> Dim loConnect = loFactory.Connect(sAddress, Val(sPort))
> lConnectionOk = True
> Catch ex As Exception
> lConnectionOk = False
>
> End Try
> If lConnectionOk Then
> Try
> loConnect.sendmessage(sParsedMessage)
> ' Disconnect
> loConnect.disconnect()
> Catch ex As Exception
> End Try
> End If
>