all groups > vb.net > january 2008 >
You're in the vb.net group:
Instantiating object returns nothing
vb.net:
What is the error? On Thu, 31 Jan 2008 15:59:57 +1100, "Rotsey" [quoted text, click to view] <malcolm_smith@RemoveThis.optusnet.com.au> wrote: >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
What happens if you replace:- Public objSI As TBRSendDocInfo with Public objSI As New TBRSendDocInfo does that result in a valid object? Guy [quoted text, click to view] "Rotsey" wrote: > 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 > >
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 "Rotsey" <malcolm_smith@RemoveThis.optusnet.com.au> schreef in bericht news:u7fLdY8YIHA.4160@TK2MSFTNGP03.phx.gbl... [quoted text, click to view] > 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 > >
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... -- Patrice "Rotsey" <malcolm_smith@RemoveThis.optusnet.com.au> a écrit dans le message de news: u7fLdY8YIHA.4160@TK2MSFTNGP03.phx.gbl... [quoted text, click to view] > 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 > >
"Rotsey" <malcolm_smith@RemoveThis.optusnet.com.au> schrieb [quoted text, click to view] > 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? [quoted text, click to view] > objSD = clsServiceDefaults.Load("C:\Windows\TBRServices.xml",
"Armin Zingler" <az.nospam@freenet.de> schrieb [quoted text, click to view] > "Rotsey" <malcolm_smith@RemoveThis.optusnet.com.au> schrieb > > 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",
Forget my posting. I was wrong.
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
As I said the line is objSI = new TBRSendDocInfo before etc etc [quoted text, click to view] "Cor Ligthert[MVP]" <notmyfirstname@planet.nl> wrote in message news:7D6C7085-DE56-421C-8C68-25B411FDA6AE@microsoft.com... > 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 > > "Rotsey" <malcolm_smith@RemoveThis.optusnet.com.au> schreef in bericht > news:u7fLdY8YIHA.4160@TK2MSFTNGP03.phx.gbl... >> 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 >> >> >
Don't see what you're looking for? Try a search.
|
|
|