Instantiating object returns nothing


R

Rotsey

Hi,

I have this code. Which is the beginning of class. The last line
objSI = new TBRSendDocInfo has an error when this code
executes objSI is nothing.

What would cause a object not be able to instantiate it???

The object TBRSendDocInfo definition is below this code.

<Transaction(TransactionOption.RequiresNew)> Public Class
TransTimesheetWeekly
Inherits ServicedComponent

Public objSI As TBRSendDocInfo

Private CapType As String

Private CapID As Integer

Private justTimesheet As Boolean

Private SickDefault As Date = "01/01/1980"

Private HolidayDefault As Date = "01/01/1981"

Private LWOPDefault As Date = "01/01/1982"

Private Const WorkedDefault As String = "01/01/1984"

Private Const NotWorkedDefault As String = "01/01/1985"

Public Function ProcessTimesheetWeekly(ByVal tswID As Integer) As Integer

objSD = clsServiceDefaults.Load("C:\Windows\TBRServices.xml",
GetType(clsServiceDefaults))

Connstr = objSD.TBRConnCap

WebConnstr = objSD.TBRWebConnCap

gTestEmail = objSD.TestEmailCap

Dim objCI As New tblCapturedInvoices(mdsDatabaseV3.mdsDbType.dbSQL)

Dim objTW As New tblwebTimesheetWeekly(mdsDatabaseV3.mdsDbType.dbSQL)

Dim objDB As New mdsDatabaseV3.cMDSTableData(Connstr,
mdsDatabaseV3.mdsDbType.dbSQL)

Dim objWDB As New mdsDatabaseV3.cMDSTableData(WebConnstr,
mdsDatabaseV3.mdsDbType.dbSQL)

Dim objDR As SqlClient.SqlDataReader

Dim objPR As SqlClient.SqlDataReader

Dim SQL, s As String

Dim i, j, wk, newID, wksInv As Integer

Dim objR As DataRow

Dim submitted As Date

Try

objSI = New TBRSendDocInfo

etc

etc











Imports System.Xml.Serialization

Imports System.IO

Public Class PDFDocInfo

Public InputFile As String

Public DocType As String

Public OutputFile As String

End Class

Public Class TBRSendDocInfo

Public ID As Integer

Public FirstName As String

Public LastName As String

Public Email As String

Public RecipientName As String

Public Subject As String

Public Body As String

Public LesterUser As String

Public FromEmail As String

<XmlIgnore()> Public PDFDocs As New ArrayList

Public Sub AddPDFDocInfo(ByVal pdfinfo As PDFDocInfo)

PDFDocs.Add(pdfinfo)

End Sub

Public Function AddNewPDFDocInfo() As PDFDocInfo

Dim newPDFDocInfo As New PDFDocInfo

PDFDocs.Add(newPDFDocInfo)

Return newPDFDocInfo

End Function

Public Property SendPDFDocs() As PDFDocInfo()

Get

Dim numPDFDocs As Integer

If PDFDocs.Count = 0 Then

numPDFDocs = 0

Else

numPDFDocs = PDFDocs.Count - 1

End If

Dim PDFDocInfoArray(numPDFDocs) As PDFDocInfo

PDFDocs.CopyTo(PDFDocInfoArray)

Return PDFDocInfoArray

End Get

Set(ByVal Value As PDFDocInfo())

PDFDocs.Clear()

If Not Value Is Nothing Then

Dim PDFDocInfo As PDFDocInfo

For Each PDFDocInfo In Value

PDFDocs.Add(PDFDocInfo)

Next

End If

End Set

End Property

Public Function Save(ByVal filename As String)

Dim tempFilename As String

tempFilename = filename & ".tmp"

Dim tempFileInfo As New FileInfo(tempFilename)

If tempFileInfo.Exists = True Then tempFileInfo.Delete()

Dim stream As New FileStream(tempFilename, FileMode.Create)

Try

Save(stream)

stream.Close()

tempFileInfo.CopyTo(filename, True)

tempFileInfo.Delete()

Catch ex As Exception

MsgBox("Error on Save of file " & filename & ". " & vbCrLf & ex.Message)

End Try

End Function

Public Function Save(ByVal stream As Stream)

Dim serializer As New XmlSerializer(Me.GetType)

serializer.Serialize(stream, Me)

End Function

Public Shared Function Load(ByVal filename As String, ByVal newType As Type)
As Object

Dim fileInfo As New FileInfo(filename)

If fileInfo.Exists = False Then

Return System.Activator.CreateInstance(newType)

End If

Dim stream As New FileStream(filename, FileMode.Open)

Dim newObject As Object = Load(stream, newType)

stream.Close()

Return newObject

End Function

Public Shared Function Load(ByVal stream As Stream, ByVal newType As Type)
As Object

Dim serializer As New XmlSerializer(newType)

Dim newObject As Object = serializer.Deserialize(stream)

Return newObject

End Function



End Class
 
Ad

Advertisements

C

Cor Ligthert[MVP]

Rotsey,

Can you give us an idea at what point that messages is showed up.

I see a bunch of code, however in my idea not related to your question.

Cor
 
J

Jack Jackson

What is the error?

Hi,

I have this code. Which is the beginning of class. The last line
objSI = new TBRSendDocInfo has an error when this code
executes objSI is nothing.

What would cause a object not be able to instantiate it???

The object TBRSendDocInfo definition is below this code.

<Transaction(TransactionOption.RequiresNew)> Public Class
TransTimesheetWeekly
Inherits ServicedComponent

Public objSI As TBRSendDocInfo

Private CapType As String

Private CapID As Integer

Private justTimesheet As Boolean

Private SickDefault As Date = "01/01/1980"

Private HolidayDefault As Date = "01/01/1981"

Private LWOPDefault As Date = "01/01/1982"

Private Const WorkedDefault As String = "01/01/1984"

Private Const NotWorkedDefault As String = "01/01/1985"

Public Function ProcessTimesheetWeekly(ByVal tswID As Integer) As Integer

objSD = clsServiceDefaults.Load("C:\Windows\TBRServices.xml",
GetType(clsServiceDefaults))

Connstr = objSD.TBRConnCap

WebConnstr = objSD.TBRWebConnCap

gTestEmail = objSD.TestEmailCap

Dim objCI As New tblCapturedInvoices(mdsDatabaseV3.mdsDbType.dbSQL)

Dim objTW As New tblwebTimesheetWeekly(mdsDatabaseV3.mdsDbType.dbSQL)

Dim objDB As New mdsDatabaseV3.cMDSTableData(Connstr,
mdsDatabaseV3.mdsDbType.dbSQL)

Dim objWDB As New mdsDatabaseV3.cMDSTableData(WebConnstr,
mdsDatabaseV3.mdsDbType.dbSQL)

Dim objDR As SqlClient.SqlDataReader

Dim objPR As SqlClient.SqlDataReader

Dim SQL, s As String

Dim i, j, wk, newID, wksInv As Integer

Dim objR As DataRow

Dim submitted As Date

Try

objSI = New TBRSendDocInfo

etc

etc











Imports System.Xml.Serialization

Imports System.IO

Public Class PDFDocInfo

Public InputFile As String

Public DocType As String

Public OutputFile As String

End Class

Public Class TBRSendDocInfo

Public ID As Integer

Public FirstName As String

Public LastName As String

Public Email As String

Public RecipientName As String

Public Subject As String

Public Body As String

Public LesterUser As String

Public FromEmail As String

<XmlIgnore()> Public PDFDocs As New ArrayList

Public Sub AddPDFDocInfo(ByVal pdfinfo As PDFDocInfo)

PDFDocs.Add(pdfinfo)

End Sub

Public Function AddNewPDFDocInfo() As PDFDocInfo

Dim newPDFDocInfo As New PDFDocInfo

PDFDocs.Add(newPDFDocInfo)

Return newPDFDocInfo

End Function

Public Property SendPDFDocs() As PDFDocInfo()

Get

Dim numPDFDocs As Integer

If PDFDocs.Count = 0 Then

numPDFDocs = 0

Else

numPDFDocs = PDFDocs.Count - 1

End If

Dim PDFDocInfoArray(numPDFDocs) As PDFDocInfo

PDFDocs.CopyTo(PDFDocInfoArray)

Return PDFDocInfoArray

End Get

Set(ByVal Value As PDFDocInfo())

PDFDocs.Clear()

If Not Value Is Nothing Then

Dim PDFDocInfo As PDFDocInfo

For Each PDFDocInfo In Value

PDFDocs.Add(PDFDocInfo)

Next

End If

End Set

End Property

Public Function Save(ByVal filename As String)

Dim tempFilename As String

tempFilename = filename & ".tmp"

Dim tempFileInfo As New FileInfo(tempFilename)

If tempFileInfo.Exists = True Then tempFileInfo.Delete()

Dim stream As New FileStream(tempFilename, FileMode.Create)

Try

Save(stream)

stream.Close()

tempFileInfo.CopyTo(filename, True)

tempFileInfo.Delete()

Catch ex As Exception

MsgBox("Error on Save of file " & filename & ". " & vbCrLf & ex.Message)

End Try

End Function

Public Function Save(ByVal stream As Stream)

Dim serializer As New XmlSerializer(Me.GetType)

serializer.Serialize(stream, Me)

End Function

Public Shared Function Load(ByVal filename As String, ByVal newType As Type)
As Object

Dim fileInfo As New FileInfo(filename)

If fileInfo.Exists = False Then

Return System.Activator.CreateInstance(newType)

End If

Dim stream As New FileStream(filename, FileMode.Open)

Dim newObject As Object = Load(stream, newType)

stream.Close()

Return newObject

End Function

Public Shared Function Load(ByVal stream As Stream, ByVal newType As Type)
As Object

Dim serializer As New XmlSerializer(newType)

Dim newObject As Object = serializer.Deserialize(stream)

Return newObject

End Function



End Class
 
P

Patrice

The error message should tell us more. Make sure the Try block you start
(but we don't know what you do then) doesn't hide the exception that should
happen when this class is created...
 
A

Armin Zingler

Rotsey said:
Hi,

I have this code. Which is the beginning of class. The last line
objSI = new TBRSendDocInfo has an error when this code
executes objSI is nothing.

Maybe because you assign it to objSD, not objSI?
objSD = clsServiceDefaults.Load("C:\Windows\TBRServices.xml",



Armin
 
Ad

Advertisements

Ad

Advertisements

G

guy

What happens if you replace:-

Public objSI As TBRSendDocInfo

with

Public objSI As New TBRSendDocInfo

does that result in a valid object?

Guy
 

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

Top