Click to See Complete Forum and Search --> : Trapping Events in Formless Apps
Cranky
Aug 11th, 2000, 12:11 AM
I am trying to use Winsock without a form and can't figure out how to trap events such as DataArrival and Error.
Private Sub g_objWs_DataArrival(ByVal bytesTotal As Long)
doesn't seem to get called.
Can someone tell me how to do this?
Thanks
ShadowWal
Aug 11th, 2000, 12:44 AM
did you do these few things:
Winsock1.RemoteHost = "www.host.com"
Winsock1.RemotePort = 80
Winsock1.Connect
Private Sub Winsock1_Connect()
Dim strCommand As String
Dim strWebPage As String
strWebPage = "http://www.host.com/urpage.htm"
strCommand = "GET " + strWebpage + " HTTP/1.0" + vbCrLf
strCommand = strCommand + "Accept: */*" + vbCrLf
strCommand = strCommand + "Accept: text/html" + vbCrLf
strCommand = strCommand + vbCrLf
Winsock1.SendData strCommand
End Sub
after those two things, the dataarrival will be called. and you will have access to the error part also
Cranky
Aug 11th, 2000, 09:04 AM
Thanks for the reply.
In the following snippet, Sub g_objWs_Connect() is never called.
----------------------------------------
Public g_objWs As MSWinsockLib.Winsock
Sub Main()
Set g_objWs = New MSWinsockLib.Winsock
g_objWs.RemoteHost = udtParms.strAddress
g_objWs.RemotePort = MAILPORT
g_objWs.Connect
While g_objWs.State <> sckConnected
DoEvents
Wend
MsgBox "Connected"
End Sub
Private Sub g_objWs_Connect()
MsgBox "connect event"
End Sub
-----------------------------------------
I have code that works fine when I drag a Winsock component onto a form, but my app will run as a formless background task.
Thanks,
Cranky
ShadowWal
Aug 11th, 2000, 01:34 PM
did u load a control for winsock at runtime? that really is the only thing i can think ove. i can remember how to load it at runtime but i know i read it in one of the posts in here. so maybe that is what is wrong
Cranky
Aug 12th, 2000, 01:18 PM
Hey, thanks for sticking with me on this.
>>did u load a control for winsock at runtime?
I think that:
Set g_objWs = New MSWinsockLib.Winsock
does this.
Anyway, I gave up and used an invisible form with the winsock component on it.
Thanks again,
Cranky
ShadowWal
Aug 12th, 2000, 02:19 PM
sorry i couldnt help anymore. i havnt gotten to the point of using a formless progi yet. im sure to have the same problem if i ever do =)
parksie
Aug 12th, 2000, 05:00 PM
Check out the WithEvents keyword. Basically, you declare your Winsock control, but add WithEvents after the Dim (or something like that). Then, add declarations for the events, and it works! (we hope)
gwdash
Aug 12th, 2000, 06:22 PM
i havn't tried it, but i think parksie is right with the WithEvents buissiness.
Clunietp
Aug 14th, 2000, 11:17 AM
First you must add a reference to MS Winsock. This MUST be done through PROJECT --> REFERENCES and NOT PROJECT --> COMPONENTS. Just browse to MSWinsck.ocx using the browse button.
Then add this code to a class module
Private WithEvents m_objSock As MSWinsockLib.Winsock
Private Sub Class_Initialize()
Set m_objSock = New MSWinsockLib.Winsock
End Sub
You can then capture Winsock events without using forms
Tom
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.