REMOTE LOGGING USING WINSOCK ( Visual Basic)

The program below has been tested You don't have to create a beautiful form for it. But you need to run this program while you are away. In other words you need to have a server using some kind of fixed IP. Just place a winsock controll and copy the codes below and paste it in your form.

I don't find it usefull to do the remote logging because my logbook is already in my laptop. If you keep it in the server the program below can help. I choose this methodolgy because it is very much simpler than using Php-MySql or asp-mysql.

 

Private Sub Command2_Click()
Unload Me
End Sub

Private Sub Form_Load()
Me.Top = 0
Me.Left = 0
End Sub

Private Sub Timer1_Timer()
If Winsock1.State <> sckConnected Then
Winsock1.Close
Winsock1.LocalPort = 7000
Winsock1.Listen
End If
End Sub

Private Sub tutup_Click()
End
End Sub

Private Sub Winsock1_Connect()
Me.Caption = "CONNECTED"
End Sub


Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
If Winsock1.State <> sckConnected Then
Winsock1.Close
Winsock1.Accept requestID
End If
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim ayat As String
Winsock1.GetData ayat
Data1.Recordset.AddNew
Label2 = ayat
For i = 1 To Len(ayat)
If Mid(ayat, i, 2) = "X2" Then Data1.Recordset("date") = info: Me.Caption = info: info = "": i = i + 1: GoTo KEL
If Mid(ayat, i, 2) = "X3" Then Data1.Recordset("time") = info: info = "": i = i + 1: GoTo KEL
If Mid(ayat, i, 2) = "X4" Then Data1.Recordset("mode") = info: info = "": i = i + 1: GoTo KEL
If Mid(ayat, i, 2) = "X5" Then Data1.Recordset("frequency") = info: info = "": i = i + 1: GoTo KEL
If Mid(ayat, i, 2) = "X6" Then Data1.Recordset("callsign") = info: info = "": i = i + 1: GoTo KEL
If Mid(ayat, i, 2) = "X7" Then Data1.Recordset("name1") = info: info = "": i = i + 1: GoTo KEL
If Mid(ayat, i, 2) = "X8" Then Data1.Recordset("his_rst") = info: info = "": i = i + 1: GoTo KEL
If Mid(ayat, i, 2) = "X9" Then Data1.Recordset("my_rst") = info: info = "": i = i + 1: GoTo KEL
If Mid(ayat, i, 2) = "0" Then Data1.Recordset("address1") = info: info = "":
info = info + Mid(ayat, i, 1)
KEL:
Next

Data1.Recordset.Update
Data1.Recordset.MoveLast

End Sub


Now you are away and have a laptop and want to send the data to your log in the server at home. You can run the program below.
Simple eh ?

Simple but if it it works, it workd  like magic.

Private Sub Command1_Click()
Text1.SetFocus
End Sub
Private Sub Command2_Click()
End
End Sub

Private Sub Command3_Click()
If Winsock1.State = sckConnected Then Winsock1.SendData Trim(Text1) + "X2" + Trim(Text2) + "X3" + Trim(Text3) + "X4" + Trim(Text4) + "X5" + Trim(Text5) + "X6" + Trim(Text6) + "X7" + Trim(Text7) + "X8" + Trim(Text8) + "X9" + Trim(Text9) + "0"
End Sub

' We don't want to leave any textbox empty. So we place it with ( - ) if it is empty
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Winsock1.State = sckConnected Then Text2.SetFocus 
End Sub

Private Sub Text1_LostFocus()
If Len(Trim(Text1)) = 0 Then Text1 = "-"
End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Winsock1.State = sckConnected Then Text3.SetFocus
End Sub

Private Sub Text2_LostFocus()
If Len(Trim(Text2)) = 0 Then Text2 = "-"
End Sub

Private Sub Text3_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Winsock1.State = sckConnected Then Text4.SetFocus
End Sub

Private Sub Text3_LostFocus()
If Len(Trim(Text3)) = 0 Then Text3 = "-"
End Sub

Private Sub Text4_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Winsock1.State = sckConnected Then Text5.SetFocus
End Sub

Private Sub Text4_LostFocus()
If Len(Trim(Text4)) = 0 Then Text4 = "-"
End Sub

Private Sub Text5_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Winsock1.State = sckConnected Then Text6.SetFocus
End Sub

Private Sub Text5_LostFocus()
If Len(Trim(Text5)) = 0 Then Text5 = "-"
End Sub

Private Sub Text6_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Winsock1.State = sckConnected Then Text7.SetFocus
End Sub

Private Sub Text6_LostFocus()
If Len(Trim(Text6)) = 0 Then Text6 = "-"
End Sub

Private Sub Text7_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Winsock1.State = sckConnected Then Text8.SetFocus
End Sub

Private Sub Text7_LostFocus()
If Len(Trim(Text7)) = 0 Then Text7 = "-"
End Sub

Private Sub Text8_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Winsock1.State = sckConnected Then Text9.SetFocus
End Sub

Private Sub Text8_LostFocus()
If Len(Trim(Text8)) = 0 Then Text8 = "-"
End Sub

Private Sub Text9_LostFocus()
If Len(Trim(Text9)) = 0 Then Text9 = "-"
End Sub

Private Sub Timer1_Timer()
On Error Resume Next
If Winsock1.State <> sckConnected Then
Winsock1.Close
Winsock1.Connect "127.0.0.1", 7000 ' replace 127.0.0.1 with your domain
End If
End Sub

Private Sub Winsock1_Connect()
Me.Caption = "OK"
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim ayat As String
Winsock1.GetData ayat
Me.Caption = ayat
End Sub

Picture below showing the server side at your home and the client at your laptop. While you are away you can controll your home radio form your mobile unit. 

My coding is free and everyone can modify it but don't claim you start and invent everything hi...

Client side on your laptop

Private Sub Command1_Click()
Text1.SetFocus
End Sub
Private Sub Command2_Click()
End
End Sub

Private Sub Command3_Click()
If Winsock1.State = sckConnected Then Winsock1.SendData Trim(Text1) + "X2" + Trim(Text2) + "X3" + Trim(Text3) + "X4" + Trim(Text4) + "X5" + Trim(Text5) + "X6" + Trim(Text6) + "X7" + Trim(TextX7) + "X8" + Trim(Text8) + "X9" + Trim(Text9) + "0"
End Sub

Private Sub Command4_Click()
If Winsock1.State = sckConnected Then Winsock1.SendData "cmd2"
End Sub

Private Sub Command5_Click()
If Winsock1.State = sckConnected Then Winsock1.SendData "cmd1"
End Sub

Private Sub Command6_Click()
If Winsock1.State = sckConnected Then Winsock1.SendData "cmd3"

End Sub

Private Sub Command7_Click()
If Winsock1.State = sckConnected Then Winsock1.SendData "cmd4"

End Sub

Private Sub Command8_Click()
If Winsock1.State = sckConnected Then Winsock1.SendData "cmd6"

End Sub

Private Sub Command9_Click()
If Winsock1.State = sckConnected Then Winsock1.SendData "cmd5"

End Sub

Private Sub Option4_Click(Index As Integer)
If Winsock1.State = sckConnected Then Winsock1.SendData Index & "mode"
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Winsock1.State = sckConnected Then Text2.SetFocus ' We don't want to leave the textbox empty.
End Sub

Private Sub Text1_LostFocus()
If Len(Trim(Text1)) = 0 Then Text1 = "-"
End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Winsock1.State = sckConnected Then Text3.SetFocus
End Sub

Private Sub Text2_LostFocus()
If Len(Trim(Text2)) = 0 Then Text2 = "-"
End Sub

Private Sub Text3_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Winsock1.State = sckConnected Then Text4.SetFocus
End Sub

Private Sub Text3_LostFocus()
If Len(Trim(Text3)) = 0 Then Text3 = "-"
End Sub

Private Sub Text4_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Winsock1.State = sckConnected Then Text5.SetFocus
End Sub

Private Sub Text4_LostFocus()
If Len(Trim(Text4)) = 0 Then Text4 = "-"
End Sub

Private Sub Text5_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Winsock1.State = sckConnected Then Text6.SetFocus
End Sub

Private Sub Text5_LostFocus()
If Len(Trim(Text5)) = 0 Then Text5 = "-"
End Sub

Private Sub Text6_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Winsock1.State = sckConnected Then Text7.SetFocus
End Sub

Private Sub Text6_LostFocus()
If Len(Trim(Text6)) = 0 Then Text6 = "-"
End Sub

Private Sub Text7_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Winsock1.State = sckConnected Then Text8.SetFocus
End Sub

Private Sub Text7_LostFocus()
If Len(Trim(Text7)) = 0 Then Text7 = "-"
End Sub

Private Sub Text8_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Winsock1.State = sckConnected Then Text9.SetFocus
End Sub

Private Sub Text8_LostFocus()
If Len(Trim(Text8)) = 0 Then Text8 = "-"
End Sub

Private Sub Text9_LostFocus()
If Len(Trim(Text9)) = 0 Then Text9 = "-"
End Sub

Private Sub Timer1_Timer()
On Error Resume Next
If Winsock1.State <> sckConnected Then
Winsock1.Close
Winsock1.Connect "127.0.0.1", 7000 ' replace 127.0.0.1 with your domain
End If
End Sub

Private Sub Winsock1_Connect()
Me.Caption = "Connected to host computer"
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim ayat As String
Winsock1.GetData ayat
Text10 = ayat
End Sub

Server side at your home.

Private Sub Text3_Change()
If Winsock1.State = sckConnected Then Winsock1.SendData Text3
End Sub

Private Sub Timer1_Timer()
If Winsock1.State <> sckConnected Then
Winsock1.Close
Winsock1.LocalPort = 7000
Winsock1.Listen
End If
End Sub

Private Sub tutup_Click()
End
End Sub

Private Sub Timer3_Timer()
On Error GoTo kel
inbuff = MSComm1.Input
numbe = 0
For i = Len(inbuff) To 1 Step -1
'an = Hex(Asc(Mid(inbuff, i, 2))): htd
numbe = numbe + 1
'Text1 = Text1 & Hex(Asc(Mid(inbuff, i, 2))) & " "
ang(numbe) = Hex(Asc(Mid(inbuff, i, 2)))
Next

If Val(ang(4)) < 10 And Len(ang(4)) < 2 Then ang(4) = "0" + ang(4)
If Val(ang(5)) < 10 And Len(ang(5)) < 2 Then ang(5) = "0" + ang(5)
If Val(ang(6)) < 10 And Len(ang(6)) < 2 Then ang(6) = "0" + ang(6)


aya = ang(2) + ang(3) + ang(5) + ang(6) + "ang(4)"
'If InStr(aya, "E") > 0 Or InStr(aya, "F") > 0 Then GoTo kel
Text3 = ang(2) + ang(3) + "." + ang(4) + Left(ang(5), 1) + "." + Right(ang(5), 1) + ang(6): Exit Sub
'MSComm1.Output = Chr(254) & Chr(254) & Chr(xx) & Chr(224) & Chr(3) & Chr(253)
kel:
If Err = 8018 Then Exit Sub
MSComm1.Output = Chr(254) & Chr(254) & Chr(xx) & Chr(224) & Chr(3) & Chr(253)

kel2:

End Sub

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
If Winsock1.State <> sckConnected Then
Winsock1.Close
Winsock1.Accept requestID
End If
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim ayat As String
Winsock1.GetData ayat
If InStr(ayat, "cmd1") > 0 Then Call Command3_Click: Exit Sub 'move memeory channel up
If InStr(ayat, "cmd2") > 0 Then Call Command4_Click: Exit Sub 'move memeory channel down
If InStr(ayat, "cmd3") > 0 Then Call Command6_Click: Exit Sub 'set memeory channel
If InStr(ayat, "cmd4") > 0 Then Call Command7_Click: Exit Sub 'set vfo channel
If InStr(ayat, "cmd5") > 0 Then Call Command5_Click: Exit Sub 'disp frequency
If InStr(ayat, "cmd6") > 0 Then Call Command8_Click: Exit Sub 'memory write
If InStr(ayat, "mode") > 0 Then Option4(Val(Left(ayat, 1))).Value = True: Exit Sub
Data1.Recordset.AddNew
Label2 = ayat
For i = 1 To Len(ayat)
If Mid(ayat, i, 2) = "X2" Then Data1.Recordset("date") = info: Me.Caption = info: info = "": i = i + 1: GoTo kel
If Mid(ayat, i, 2) = "X3" Then Data1.Recordset("time") = info: info = "": i = i + 1: GoTo kel
If Mid(ayat, i, 2) = "X4" Then Data1.Recordset("mode") = info: info = "": i = i + 1: GoTo kel
If Mid(ayat, i, 2) = "X5" Then Data1.Recordset("frequency") = info: info = "": i = i + 1: GoTo kel
If Mid(ayat, i, 2) = "X6" Then Data1.Recordset("callsign") = info: info = "": i = i + 1: GoTo kel
If Mid(ayat, i, 2) = "X7" Then Data1.Recordset("name1") = info: info = "": i = i + 1: GoTo kel
If Mid(ayat, i, 2) = "X8" Then Data1.Recordset("his_rst") = info: info = "": i = i + 1: GoTo kel
If Mid(ayat, i, 2) = "X9" Then Data1.Recordset("my_rst") = info: info = "": i = i + 1: GoTo kel
If Mid(ayat, i, 2) = "0" Then Data1.Recordset("address1") = info: info = "":
info = info + Mid(ayat, i, 1)
kel:
Next

Data1.Recordset.Update
Data1.Recordset.MoveLast

End Sub

Below is a code which you can try to think what is it used for. gg must be declared with the initial value 0f 10. 
Private Sub Text8_Click()
Text8 = Val(Text8) + 1
If Val(Text8) = gg Then Text8 = Val(Text8) + 6: gg = gg + 16 'Why this formula ?
zzz = Val(Text8)
MSComm1.Output = Chr(254) & Chr(254) & Chr(xx) & Chr(224) & Chr(0) & Chr(zzz) & Chr(yyy) & Chr(mmm) & Chr(lll) & Chr(vvv) & Chr(253)
End Sub