Its been a while...
So I wrote up a class file..compiled to a dll in vb.net..just a simple example..here is the actual class:
Then I created a win app form to Instantiate this object and work on some methods..I created an array of Ticket.Ticket objects..(not sure why it requires me to say Ticket.Ticket and not just Dim t as Ticket alone is another issue, even though I have imported at the top Imports Ticket.Ticket). In any event when I run the following code:Code:Public Class Ticket Private lngTicketID As Long Private dtOpenDate As Date Private dtTargetDate As Date Private dtClosedDate As Date Private strTicketDescription As String Private strAssignedTo As String Public Sub New() lngTicketID = GetNextTicketID() dtOpenDate = Format(Now, "dd-MMM-yy") dtTargetDate = DateAdd(DateInterval.Day, 7, dtOpenDate) dtClosedDate = Nothing strTicketDescription = "" strAssignedTo = "" End Sub Public Function GetNextTicketID() As Long 'do some work... GetNextTicketID = 2 End Function Public ReadOnly Property TicketID() As Long Get Return lngTicketID End Get End Property Public Sub SetClosed() dtClosedDate = Format(Now, "dd-MMM-yy") End Sub Public Sub SetTicketDescription(ByVal strTD As String) strTicketDescription = strTD End Sub Public ReadOnly Property TicketDescription() As String Get Return strTicketDescription End Get End Property End Class
It sets the ticket descriptions for all five elements..then it goes to the loop to messagebox them, and displays the first one fine (objT1(0) works fine)..then it increments i and tries to display objT1(1) and it fails with System.Null exceptions...why ? I have used the New Ticket.Ticket to allocate each element in the array.Code:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim objT1(5) As Ticket.Ticket Dim i As Integer = 0 For i = 0 To objT1.Length - 1 objT1(i) = New Ticket.Ticket objT1(i).SetTicketDescription("Hi - " & i) i += 1 Next For i = 0 To objT1.Length - 1 MsgBox(objT1(i).TicketDescription) Next End Sub




Reply With Quote