I am working on a project and I need to use VB. I am passing data from a Class to a Form like this:
In Class1
In Class2
Then obviously there would be code in the form to handle the data in the collection I return.
Is this the best way to do something like this in visual basic or are there better ways?
Many Thanks,
TrUz
In Class1
Code:
Option Explicit
Public FirstName as String
Public LastName as String
public RecordFound as Boolean
In Class2
Code:
Option Explicit
Dim sql as String
Dim cnn as ADODB.Connection
Dim rst as ADODB.Recorset
Public Function GetData() as Collection
Dim tmpCollection as Collection
Dim tmpClass1 as Class1
sql = "select * from table"
Set cnn = New ADODB.Connection
cnn.Open "Connection String"
Set rst = New ADODB.Recordset
rst.Open sql, cnn
Set tmpCollection = New Collection
If (rst.RecordCount = 1)
Set tmpClass1 = New Class1
tmpClass1.FirstName = rst(0)
tmpClass1.LastName = rst(1)
tmpClass1.RecordFound = True
Else
tmpClass1.RecordFound = Flase
End If
tmpCollection.Add tmpClass1
rst.Close
cnn.Close
Set GetData = tmpCollection
set rst = Nothing
set cnn = Nothing
set tmpClass1 = Nothing
set tmpCollection = Nothing
End Function
Is this the best way to do something like this in visual basic or are there better ways?
Many Thanks,
TrUz