i'm using VB.net 2003 application program. i'm trying to convert a VB6 program to VB.NET. The VB6 code i'm trying to convert is shown below.
declared g_Share() array in module and trying to add values to it inside form.
and i tried to convert the above code to vb.net as shown below.
when pgm runs and when it reach ".PrinterName = myReader(0)" line, it crashes.
how can i create dynamic array for user-defined type in vb.net?
If you have any idea how to do this, please let me know and if you can provide an example, then it will be great help for me.
Thanks in advance.
declared g_Share() array in module and trying to add values to it inside form.
VB.NET:
[COLOR="Red"]VB6 (Code inside Module)[/COLOR]
'Global type array to hold printer info.
Public Type OShare
PrinterName As String
BackupName As String
CurrId as Integer
End Type
'Declare dynamic array for printer info as user-defined type declared above.
Public g_Share() As OShare
[COLOR="Red"]VB6 (Code inside Form)[/COLOR]
Public Sub LoadPrinters()
Dim dbPrinters As DAO.Database
Dim rsPrinters As DAO.Recordset
Dim intPosition As Integer
Set rsPrinters = dbPrinters.OpenRecordset("SELECT * FROM Printer")
Do Until rsPrinters.EOF
'This variable holds the current position of the recordset
intPosition = rsPrinters.AbsolutePosition
'Load the array with the printer info.
With g_Share(intPosition)
If Not IsNull(rsPrinters!PrinterName) Then
.PrinterName = Trim(rsPrinters!PrinterName)
End If
If Not IsNull(rsPrinters!BackupPath) Then
.BackupName = Trim(rsPrinters!BackupPath)
End If
End With
rsPrinters.MoveNext
Loop
rsPrinters.Close
dbPrinters.Close
End Sub
Public Sub Add_ComboBox(intPrinter As Integer)
g_Share(intPrinter).CurrID = "120"
cboPrinters.AddItem g_Share(intPrinter).PrinterName, intPrinter
End Sub
and i tried to convert the above code to vb.net as shown below.
VB.NET:
[COLOR="Red"]VB.NET (Code inside Module)[/COLOR]
'Declare dynamic array for printer info as user-defined type declared above.
Public g_Share() As OShare
'Global type array to hold printer info.
Public Class OShare
Public PrinterName As String
Public BackupName As String
Public CurrId as Integer
End Class
[COLOR="Red"]VB.NET (Code inside Form)[/COLOR]
Public Sub LoadPrinters()
Dim intPosition As Integer = 0
myConnection.Open()
strSQL = "SELECT PrinterName, BackupPath FROM Printer"
myCommand = New OleDbCommand(strSQL, myConnection)
myReader = myCommand.ExecuteReader
While myReader.Read
'This variable holds the current position of the recordset
intPosition = intPosition
'Load the array with the printer info.
With g_Share(intPosition)
If Not IsDBNull(myReader(0)) Then .PrinterName = myReader(0)
If Not IsDBNull(myReader(1)) Then .BackupName = myReader(1)
End With
intPosition = intPosition + 1
End While
myReader.Close()
myConnection.Close()
End Sub
Public Sub Add_ComboBox(intPrinter As Integer)
g_Share(intPrinter).CurrID = "120"
cboPrinters.Items.Add(g_Share(intPrinter).PrinterName)
End Sub
when pgm runs and when it reach ".PrinterName = myReader(0)" line, it crashes.
using immediate window i can see the myReader(0) value.Object reference not set to an instance of an object.
how can i create dynamic array for user-defined type in vb.net?
If you have any idea how to do this, please let me know and if you can provide an example, then it will be great help for me.
Thanks in advance.