August 5th, 2002, 06:24 AM
Making a Connection & Safely Sending a String All in VisualBasic
This is a very short tutorial and isn't much of a highly thought out one, but I will be making short tut's on neat VisualBasic tricks. Hope you enjoy!
Making a Connection Code Snippet
This is the common way to make a connection in any VisualBasic project. It is used widely in p2p applications, and most internet related VisualBasic projects.
Private Sub cmdConnect_Click()
' set up the Winsock properties
' and start the connect sequence
Winsock.RemoteHost = "127.0.0.1"
Winsock.RemotePort = "12345"
Private Sub Winsock_Connect()
' we're connected
MsgBox "Connected to: " & Winsock.RemoteHostIP
Private Sub sckMain_Error(ByVal Number As Integer, Description As String, _
ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, _
ByVal HelpContext As Long, CancelDisplay As Boolean)
' alert the user to the error
MsgBox "Error: " & Description
Safely Sending a String Snippet
Now, to safely send a string through the VisualBasic language. This is also used in p2p applications and internet based programs for sending and recieving strings or data.
Public Function WinsockSend(pSock As Winsock, ByVal Data As String) As Boolean
' send the data on the passed winsock
If pSock.State = sckConnected Then
' send the data and return true
WinsockSend = True
' return false because we're not connected
WinsockSend = False
Or, for sckMain:
' instead of using this to send data
If sckMain.State = sckConnected Then
' i can use this
blnRetVal = WinsockSend(sckMain, strData)
Simple, and to the point. That's it! Next issue will be basic p2p chat creating in VisualBasic. Enjoy!
August 5th, 2002, 07:13 AM
Thanks JC this is why I came to AO, I will keep looking for more of these.
I have a question; are you the bug, or the windshield?
August 5th, 2002, 07:19 AM
Thanks, Im going to have more VisualBasic tutorials in the future.
August 5th, 2002, 08:36 PM
Very cool. I look forward to the rest of them you make.
August 5th, 2002, 08:43 PM
Thanks, I'll have prolly around two more VisualBasic related one's that should come out within this week.
August 5th, 2002, 08:48 PM
Thanks JC another little bit of code to but in the ol' tool kit. If I were not so busy looking for a job I'd look over my CD's and the Win tools there anyway great short tut. Now back to my login tuts after looking a few more hours for a job.
I believe that one of the characteristics of the human race - possibly the one that is primarily responsible for its course of evolution - is that it has grown by creatively responding to failure.- Glen Seaborg
August 5th, 2002, 10:01 PM
No Problem, the next installment of the little VisualBasic set of tut's by me should be out in 2 days.
Anyone have suggestion's toward what VisualBasic tutorials I should make? I wanna make tutorials that will benefit people's needs. My next VisualBasic tutorial will be on p2p chats.
August 6th, 2002, 03:21 AM
Nice tutorial, JC. It's refreshing to finally find an interesting VB tut. The VB tuts that i usually run across usually have something to do with "The ins and outs to making a calculator". lol
I will be keeping an eye out for your next tutorial.
August 6th, 2002, 06:12 PM
Kool, Thanks Gurl. My newest one is out and is called P2P Chat's In VisualBasic. Check it out!
August 7th, 2002, 10:38 PM
Yup, that winsock control is quite handy for quick and dirty sockets...
Make sure you instal sp4 and up for vb though if you use an array of server winsock controls because there was a nasty bug before sp4 that screwd up the events from receives...
(If multiple sockets in the array received data at the same time, only one would get noticed until data stopped flowing in to the other sockets...)
I got bite by this when I was developping a final project for school work! Urgh! So maddening, I was looking everywhere in my code for days... then I found the KB article..! heh..
Credit travels up, blame travels down -- The Boss