the problem comming from frmStatus's form

S

Supra

An unhandled exception of type 'System.NullReferenceException' occurred
in system.windows.forms.dll
Additional information: Object reference not set to an instance of an
object.
i don't know how to reference from frmStatus to this class...
Option Explicit On
Option Strict Off

Imports System
Imports System.IO
Imports System.Net.Sockets
Imports System.Net.Dns

Namespace PirateChat
Public Class ClientFactory

Private clsReader As New PirateChat.clsReadWriteXML
Private WithEvents _Connection As New ConnectionFactory
Public nStatus As New frmStatus 'created new object
Public Event onSeverMessage(ByVal szText As String)
Public Event onEventHappen(ByVal szEvent As String, ByVal szText
As String, ByVal szNick As String, ByVal szChannel As String, ByVal
szHost As String)
Public Event onAltNick(ByVal lpErrCode As Integer, ByVal
szDiscription As String)
Public Event onCreate(ByVal szChannel As String, ByVal szText As
String)
Public Event onSetBy(ByVal szChannel As String, ByVal szText As
String)
Private sock As Socket
Private sr As StreamReader
Private sw As StreamWriter
Private ns As NetworkStream

Public m_NewChannel As Collection
Dim nChan As New frmChannel
Private bConnected As Boolean

#Region "Property NewChannel..."
Public Property NewChannel() As Object
Get
NewChannel = m_NewChannel
End Get
Set(ByVal Value As Object)
m_NewChannel = Value
End Set
End Property

#End Region
#Region "Property AddChannel..."

Public Sub AddChannel(ByVal szText As String)
Dim fChannel As New frmChannel
fChannel.Text = szText
m_NewChannel.Add(fChannel, szText)
fChannel.Tag = szText
End Sub
#End Region
#Region "Connect/Disconnect..."
Public Sub ConnectServer()
Dim strHostName = System.Net.Dns.GetHostName.ToString
DisplayMessage(nStatus.rtbStatus, "Your conputer name: " &
strHostName & Environment.NewLine)
DisplayMessage(nStatus.rtbStatus, "Your Address IP: " &
System.Net.Dns.GetHostByName(strHostName).AddressList(0).ToString &
Environment.NewLine)

If bConnected = True Then Exit Sub
DisplayMessage(nStatus.rtbStatus, "Attempting connection to
host..." & _Connection.ServerName.ToString & Environment.NewLine)
Try
DisplayMessage(nStatus.rtbStatus, "Connection
established..." & _Connection.ServerName.ToString & " (" &
GetHostByName(_Connection.ServerName.ToString).AddressList(0).ToString()
& ")" & Environment.NewLine)
DisplayMessage(nStatus.rtbStatus, "Connected. Now
logging in.." & Environment.NewLine)
nStatus.Text = "Status :" & _Connection.ServerName
'add server name
Catch e As SocketException
DisplayMessage(nStatus.rtbStatus, "Unknown host. Server
must be down or no longer available?" & Environment.NewLine)
End Try

With _Connection
bConnected = False
.ServerName = _Connection.ServerName
.iPort = _Connection.iPort
.Nick = _Connection.Nick
.RealName = _Connection.RealName
.UserName = _Connection.UserName
.AltName = _Connection.AltName
.Email = _Connection.Email
.Password = _Connection.Password
.IdentName = _Connection.IdentName
.IdentPort = _Connection.IdentPort
.IdentSys = _Connection.IdentSys
End With

'ns = New NetworkStream(sock) 'we can use streams on the
socket
'sr = New StreamReader(ns) 'we can used to read data
off sockect
'sw = New StreamWriter(ns) 'we can used to write data
off sockect

_Connection.Connect()
End Sub
#End Region
#Region "get infor..."
Public Sub GetInfo()
'get clients information
_Connection.ServerName = _Connection.m_SerName
_Connection.iPort = _Connection.m_Port
_Connection.Nick = _Connection.m_Nick
_Connection.RealName = _Connection.m_RealName
_Connection.UserName = _Connection.m_UserName
_Connection.AltName = _Connection.m_AltName
_Connection.Email = _Connection.m_Email
_Connection.Password = _Connection.m_Pswrd

'get ident informatiom
_Connection.IdentName = _Connection.m_IDName
_Connection.IdentPort = _Connection.m_IdPort
_Connection.IdentSys = _Connection.m_IDSys

'get dcc information
End Sub

#End Region

Public Sub New()
MyBase.GetType()
End Sub
Private m_MdiParent As mainPirateChat

Public Sub New(ByVal MdiParent As mainPirateChat)
m_MdiParent = MdiParent
' nStatus.MdiParent = m_MdiParent
End Sub

Private Sub _Connection_onSeverMessage(ByVal szText As String)
Handles _Connection.onSeverMessage
DisplayMessage(nStatus.rtbStatus, szText) <========== the
problem comming from this event
End Sub

Private Sub _Connection_onErrorMessage(ByVal szText As String)
Handles _Connection.onErrorMessage
DisplayMessage(nStatus.rtbStatus, szText.ToString)
End Sub
End Class
End Namespace
regards,
 
G

Guest

Not sure I understand your question but if all you want to do is use the
client factory class from your form, then in your form class just before the
first sub in your form class, simply instantiate an instance of the class
like:

PUblic withevents myfactory as ClientFactory

If the ClientFactory class is in a different namespace, you might have to
include an imports statement for that namespace.
 

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

Similar Threads


Top