R
RSH
Hi,
i have a situation where I need to dynamically create objects in a loop. My
question surrounds intantiation naming in such a scenerio.
Below is a snippet that is basically hardcoding each object. My problem is
that I would like to create the objects dynamically but I can't figure out
how to do it
How would I go about dynamically creating the required objects so that I
could be using anywhere from 2 - 10 etc. ?
Thanks,
Ron
for x as integer = 1 to num
If x = 1 Then
' Create Object 1 ----------------------------
oDT1 = New DataTable
oDT1 = oDS.Tables(0).Clone
For i = min To max
oDT1.ImportRow(oDS.Tables(0).Rows(i))
Next
Dim oCompanyProcess1 As New CompanyWorkerClass(oDT1, strServer, "TH1")
AddHandler oCompanyProcess1.LineProcessed, AddressOf ClickCounter
AddHandler oCompanyProcess1.Finished, AddressOf ThreadFinished
Dim t1 = New Thread(AddressOf oCompanyProcess1.ProcessDataReport)
t1.Start()
ElseIf x = 2 Then
' Create Object 2 --------------------------
oDT2 = New DataTable
oDT2 = oDS.Tables(0).Clone
For i = min To max
oDT2.ImportRow(oDS.Tables(0).Rows(i))
Next
Dim oCompanyProcess2 As New CompanyWorkerClass(oDT2, strServer, "TH2")
AddHandler oCompanyProcess2.LineProcessed, AddressOf ClickCounter
AddHandler oCompanyProcess2.Finished, AddressOf ThreadFinished
Dim t2 = New Thread(AddressOf oCompanyProcess2.ProcessDataReport)
t2.Start()
ElseIf x = 3 Then
' Create Object 3 ----------------
oDT3 = New DataTable
oDT3 = oDS.Tables(0).Clone
For i = min To max
oDT3.ImportRow(oDS.Tables(0).Rows(i))
Next
Dim oCompanyProcess3 As New CompanyWorkerClass(oDT3, strServer, "TH3")
AddHandler oCompanyProcess3.LineProcessed, AddressOf ClickCounter
AddHandler oCompanyProcess3.Finished, AddressOf ThreadFinished
Dim t3 = New Thread(AddressOf oCompanyProcess3.ProcessDataReport)
t3.Start()
next
i have a situation where I need to dynamically create objects in a loop. My
question surrounds intantiation naming in such a scenerio.
Below is a snippet that is basically hardcoding each object. My problem is
that I would like to create the objects dynamically but I can't figure out
how to do it
How would I go about dynamically creating the required objects so that I
could be using anywhere from 2 - 10 etc. ?
Thanks,
Ron
for x as integer = 1 to num
If x = 1 Then
' Create Object 1 ----------------------------
oDT1 = New DataTable
oDT1 = oDS.Tables(0).Clone
For i = min To max
oDT1.ImportRow(oDS.Tables(0).Rows(i))
Next
Dim oCompanyProcess1 As New CompanyWorkerClass(oDT1, strServer, "TH1")
AddHandler oCompanyProcess1.LineProcessed, AddressOf ClickCounter
AddHandler oCompanyProcess1.Finished, AddressOf ThreadFinished
Dim t1 = New Thread(AddressOf oCompanyProcess1.ProcessDataReport)
t1.Start()
ElseIf x = 2 Then
' Create Object 2 --------------------------
oDT2 = New DataTable
oDT2 = oDS.Tables(0).Clone
For i = min To max
oDT2.ImportRow(oDS.Tables(0).Rows(i))
Next
Dim oCompanyProcess2 As New CompanyWorkerClass(oDT2, strServer, "TH2")
AddHandler oCompanyProcess2.LineProcessed, AddressOf ClickCounter
AddHandler oCompanyProcess2.Finished, AddressOf ThreadFinished
Dim t2 = New Thread(AddressOf oCompanyProcess2.ProcessDataReport)
t2.Start()
ElseIf x = 3 Then
' Create Object 3 ----------------
oDT3 = New DataTable
oDT3 = oDS.Tables(0).Clone
For i = min To max
oDT3.ImportRow(oDS.Tables(0).Rows(i))
Next
Dim oCompanyProcess3 As New CompanyWorkerClass(oDT3, strServer, "TH3")
AddHandler oCompanyProcess3.LineProcessed, AddressOf ClickCounter
AddHandler oCompanyProcess3.Finished, AddressOf ThreadFinished
Dim t3 = New Thread(AddressOf oCompanyProcess3.ProcessDataReport)
t3.Start()
next