Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Winsock dilemma 1

Status
Not open for further replies.

NeilFrank

Programmer
Mar 12, 2000
167
0
0
CA
I’m using a Winsock control to negotiate a connection with servers that provide date and time.

The method is successful when the code is on same VB Form as the Winsock control.

However in my App, which has an MDI and several Child Forms, I would like to move the code to a Code Module - rather than having to load and unload a Form - and associate the Winsock with the MDI Form. No can do: referencing the Winsock in the Module, ie MDIMain.Winsock1, hits a brick wall.
 
Well, it may not be exactly what you want, but you can always put the winsock controls on the MDIMain form, and code it appropriately in its own code window.
You would still have to have the MDIMain form loaded to access the code...but Ime pretty sure thats not gonna be an issue. =)
Then so long as the MDIMain form is loaded (which should be always..unless you're trickier than me) you can call those winsocket code snippets (such as senddata/getdata) from other forms quite easily. ie: MDIMain.Winsocket(0).getdata
 
Clever! Hadn't thought of that. It would mean adding another 100 lines of code to the MDI Form [yes it is always loaded], though, i/o using a separate code module, but elegant nonetheless. Thank you!
 
You can use the winsock control without actually having a control on a form (or, indeed, being added as a control to the toolbox)...
 
Could you provide an example or reference pertinent to my situation
 
Sure

Projects/References/Browse...

Find and select MSWINSCK.OCX (should be in your system32 folder)

Then you can use code like:

Dim myWinsock As Winsock
Set myWinsock = New Winsock

If you need events then you can use Dim Withevents, but then it needs to go in a Class module

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top