是否可以将activex对象传递给同一个类中的另一个函数?我尝试了一些变体,但第一个代码示例是我最近尝试过的。第二组代码目前有效,但我想缩短它,以便我不必为对象的每个实例写一个单独的dunction。
这是我正在尝试的当前代码:
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf Login), "AxObjectXMFDisplay1")
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf Login), "AxObjectXMFDisplay2")
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf Login), "AxObjectXMFDisplay3")
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf Login), "AxObjectXMFDisplay4")
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf Login), "AxObjectXMFDisplay5")
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf Login), "AxObjectXMFDisplay6")
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf Login), "AxObjectXMFDisplay7")
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf Login), "AxObjectXMFDisplay8")
End Sub
Private Sub Login(disp As Object)
User = TextBox1.Text
Password = TextBox2.Text
disp.RDE_SendKeys_Hsynch(User & "@T", True, 3, 1000, "", 0, 0)
disp.RDE_SendKeys_Hsynch(Password & "@E", True, 3, 1000, "", 0, 0)
End Sub
如果我这样编写代码就可以了。
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
User = TextBox1.Text
Password = TextBox2.Text
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf Login1))
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf Login2))
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf Login3))
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf Login4))
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf Login5))
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf Login6))
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf Login7))
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf Login8))
End Sub
Private Sub Login1()
AxObjectXMFDisplay2.RDE_SendKeys_Hsynch(User & "@T", True, 3, 1000, "", 0, 0)
AxObjectXMFDisplay2.RDE_SendKeys_Hsynch(Password & "@E", True, 3, 1000, "", 0, 0)
End Sub
Private Sub Login2()
AxObjectXMFDisplay2.RDE_SendKeys_Hsynch(User & "@T", True, 3, 1000, "", 0, 0)
AxObjectXMFDisplay2.RDE_SendKeys_Hsynch(Password & "@E", True, 3, 1000, "", 0, 0)
End Sub
Private Sub Login3()
AxObjectXMFDisplay3.RDE_SendKeys_Hsynch(User & "@T", True, 3, 1000, "", 0, 0)
AxObjectXMFDisplay3.RDE_SendKeys_Hsynch(Password & "@E", True, 3, 1000, "", 0, 0)
End Sub
Private Sub Login4()
AxObjectXMFDisplay4.RDE_SendKeys_Hsynch(User & "@T", True, 3, 1000, "", 0, 0)
AxObjectXMFDisplay4.RDE_SendKeys_Hsynch(Password & "@E", True, 3, 1000, "", 0, 0)
End Sub
Private Sub Login5()
AxObjectXMFDisplay5.RDE_SendKeys_Hsynch(User & "@T", True, 3, 1000, "", 0, 0)
AxObjectXMFDisplay5.RDE_SendKeys_Hsynch(Password & "@E", True, 3, 1000, "", 0, 0)
End Sub
Private Sub Login6()
AxObjectXMFDisplay6.RDE_SendKeys_Hsynch(User & "@T", True, 3, 1000, "", 0, 0)
AxObjectXMFDisplay6.RDE_SendKeys_Hsynch(Password & "@E", True, 3, 1000, "", 0, 0)
End Sub
Private Sub Login7()
AxObjectXMFDisplay7.RDE_SendKeys_Hsynch(User & "@T", True, 3, 1000, "", 0, 0)
AxObjectXMFDisplay7.RDE_SendKeys_Hsynch(Password & "@E", True, 3, 1000, "", 0, 0)
End Sub
Private Sub Login8()
AxObjectXMFDisplay8.RDE_SendKeys_Hsynch(User & "@T", True, 3, 1000, "", 0, 0)
AxObjectXMFDisplay8.RDE_SendKeys_Hsynch(Password & "@E", True, 3, 1000, "", 0, 0)
End Sub
由于
答案 0 :(得分:0)
这确实是可能的,但在你的尝试中,你只是做得不对。
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf Login), "AxObjectXMFDisplay1")
"AxObjectXMFDisplay1"
只是一个包含ActiveX对象名称的字符串。在某些内容周围放置引号会使编译器将其解释为字符串。
要传递实际的ActiveX对象,您必须删除引号,以便引用您的实际变量/对象:
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf Login), AxObjectXMFDisplay1)
为每一行做这个,你应该好好去。
我在上面解释的这个简短的例子可以说明:
Dim MyNumber As Integer = 3 'Creates the variable 'MyNumber' and sets it to 3.
MessageBox.Show(MyNumber) 'Prints: 3
MessageBox.Show("MyNumber") 'Prints: MyNumber