ocx代码如下:
Dim cnn As New ADODB.Connection
Dim adors As New ADODB.Recordset
Private Type MyType
name As String * 5
age As Long
End Type
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)Private Sub UserControl_Initialize()
Winsock1.RemoteHost = "127.0.0.1"
Winsock1.Bind 1000
'Winsock1.Protocol = sckUDPProtocol '不知为啥 不能邦定udp协议
End SubPublic Sub sendrecord()
Dim aa As MyType
Dim aabyte() As Byte
ReDim aabyte(0 To LenB(aa) - 1) As Byte
cnn.CursorLocation = adUseClient
cnn.ConnectionString = "driver={microsoft visual foxpro driver}; sourcetype=dbf;sourcedb=d:\SBL_DATABASE"
cnn.Open
adors.Open "select * from SBL"
i = 1
Do While i <= 100000
aa.age = adors.Fields("freq").Value
aa.name = "aaaa"
CopyMemory ByVal VarPtr(aabyte(0)), ByVal VarPtr(aa), LenB(aa)
Winsock1.SendData aabyte
adors.Delete
i = i + 1
Loop
End Sub
在工程中
Dim myocx As winsock_send.UserControl1
select case num
case 1
case 2
Call myocx.sendrecord
end select问题1 在主程序中调用一个ocx 能否达到主程序与ocx异步执行?
问题2 为啥那个ocx中的winsock不能绑定协议?
问题3 在工程中使用时出错 "对象变量或WITH 块变量未设置"
ocx:
Dim cnn As New ADODB.Connection
Dim adors As New ADODB.Recordset
Private Type MyType
name As String * 5
age As Long
End Type
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)Private Sub Command1_Click()
Winsock1.RemoteHost = Trim(Text1)
End SubPrivate Sub UserControl_Initialize()
Winsock1.Protocol = sckUDPProtocol
Winsock1.Bind 2000
End SubPublic Sub sendrecord()
Dim aa As MyType
Dim aabyte() As Byte
ReDim aabyte(0 To LenB(aa) - 1) As Byte
cnn.CursorLocation = adUseClient
cnn.ConnectionString = "driver={microsoft visual foxpro driver}; sourcetype=dbf;sourcedb=d:\SBL_DATABASE"
cnn.Open
adors.Open "select * from TempSBL " & " where freq=" & Here_Ask.Freqency, cnn, 3, 3
i = 1
Do While i <= 1000 'adors.RecordCount
aa.age = adors.Fields("freq").Value
aa.name = "aaaa"
CopyMemory ByVal VarPtr(aabyte(0)), ByVal VarPtr(aa), LenB(aa)
Winsock1.SendData aabyte
adors.Delete
i = i + 1
Loop
End Sub
其他工程
Private Sub Command1_Click()
For i = 1 To 10000
If i = 1 Then UserControl11.sendrecord ‘要求对象
Next
End Sub