I'm having a trouble with VB.NET:
I've got 3 different Forms (Public Class): mainForm, plotForm and tradeForm.
Both plotForm and tradeForm call a sub which is part of mainForm, called SendHost:
Public Class mainForm
Public Sub SendHost(Text As String)
Dim OutData() As Byte = Encoding.Unicode.GetBytes(Text)
Client.BeginSend(OutData, 0, OutData.Length, SocketFlags.None, New AsyncCallback(AddressOf OnSend), Client)
End Sub
End Class
When calling from plotForm, there's no problem at all:
Public Class plotForm
Private Sub btnBuy_Click(sender As Object, e As EventArgs) Handles btnBuy.Click
mainForm.SendHost("GBuy§" & Prop.PositionID)
''' Another code here....
End Sub
End Class
However, when the same sub is called from another sub called Trade, there is a problem:
Public Class tradeForm
Private Sub Trade(sender As Object, e As EventArgs) Handles btnTrade.Click
btnTrade.Enabled = False
mainForm.SendHost("GATS§" & ID)
'More code here...
Me.Close()
End Sub
End Class
This will start the sub in mainForm, but Visual Studio tells me that "Client" is Null, giving me a NullReferenceExpection. This doesn't happen with btnBuy_Click. I dont understand this, and any hints to a solution are very welcome! Thank you! Feel free to ask anything.
plotForm and tradeForm are started like (in mainForm, different subs):
Dim TradeW As New Trade
TradeW.ShowDialog(Me)
and:
Dim plotbox As New PlotBox
plotbox.ShowDialog(Me)