Option Explicit Dim Score3 As Integer, Score1 As Integer Dim delay As Integer, ReceivedString As Boolean, Score As Integer, DirectHits As Integer, PartialHits As Integer Private Sub cmdConnect_Click() 'Command connect If txtRemoteIP.Text <> "" Then If Winsock1.State <> sckConnected Then Winsock1.Close Winsock1.RemoteHost = Trim(txtRemoteIP.Text) Winsock1.Connect Do Until Winsock1.State = sckConnected DoEvents: DoEvents: DoEvents: DoEvents: DoEvents 'Delay @ 100% CPU usage If Winsock1.State = sckError Then Exit Sub End If Loop End If End If If Winsock1.State = sckConnected Then cmdStart.Enabled = True cmdReset.Enabled = True End If End Sub Private Sub cmdDisconnect_Click() 'commmand disconnect If Winsock1.State <> sckConnected Then Exit Sub Else Winsock1.SendData ("cmdDisconnect") Do Until ReceivedString = True DoEvents: DoEvents ' Delay 100% cpu Loop ReceivedString = False cmdReset.Enabled = False Winsock1.Close End If End Sub Private Sub cmdIP_Click() txtLocalIP.Text = Winsock1.LocalIP End Sub Private Sub cmdReset_Click() Winsock1.SendData ("cmdReset") Do Until ReceivedString = True DoEvents: DoEvents Loop ReceivedString = False DirectHits = 0 PartialHits = 0 Score = 0 Call UpdateScore End Sub Private Sub cmdStart_Click() delay = 0 tmrTime.Enabled = True tmrDelay.Enabled = False picStatus.Cls picStatus.Print "Active" cmdStart.Enabled = False cmdStop.Enabled = True End Sub Private Sub cmdStop_Click() tmrDelay.Enabled = False tmrTime.Enabled = False picStatus.Cls picStatus.Print "Inactive" End Sub Private Sub Command1_Click() 'Quit If Winsock1.State <> 7 Then End Else Winsock1.SendData ("cmdDisconnect") Do Until ReceivedString = True DoEvents: DoEvents Loop Winsock1.Close End End If End Sub Private Sub Form_Load() Score3 = 0 Score1 = 0 Winsock1.Listen UpdateScore WebBrowser1.Navigate ("C:\IED_Score.html") End Sub Private Sub tmrDelay_Timer() If Score1 > 0 And Score3 > 0 Then Score1 = 0 Score3 = 0 Score = Score + 3 DirectHits = DirectHits + 1 Winsock1.SendData ("cmdScore: " & 3) Do Until ReceivedString = True DoEvents: DoEvents Loop ReceivedString = False txtScore.Text = Score tmrDelay.Enabled = False tmrTime.Enabled = True Call UpdateScore ElseIf Score1 > 0 And Not Score3 > 0 Then Score1 = 0 Score3 = 0 Score = Score + 1 PartialHits = PartialHits + 1 Winsock1.SendData ("cmdScore: " & 1) Do Until ReceivedString = True DoEvents: DoEvents Loop ReceivedString = False txtScore.Text = Score tmrDelay.Enabled = False tmrTime.Enabled = True Call UpdateScore ElseIf Not Score1 > 0 And Score3 > 0 Then Score1 = 0 Score3 = 0 Score = Score + 3 Winsock1.SendData ("cmdScore: " & 3) Do Until ReceivedString = True DoEvents: DoEvents Loop DirectHits = DirectHits + 1 ReceivedString = False txtScore.Text = Score tmrDelay.Enabled = False Call UpdateScore End If End Sub Private Sub tmrTime_Timer() If Dir$("C:\Score1.xls", vbNormal) <> "" Then Kill "C:\Score1.xls" Score1 = Score1 + 1 ElseIf Dir$("C:\Score3.xls", vbNormal) <> "" Then Kill "C:\Score1.xls" Score3 = Score3 + 1 tmrTime.Enabled = False tmrDelay.Enabled = True End If End Sub Private Sub tmrWebRefresh_Timer() WebBrowser1.Refresh tmrWebRefresh.Enabled = False End Sub Private Sub tmrWinStatus_Timer() Label3.Caption = "Winsock state: " & Winsock1.State If Winsock1.State <> 7 And Winsock1.State <> 2 And Winsock1.State <> 6 Then txtPort.Enabled = True Winsock1.Listen Else txtPort.Enabled = True End If End Sub Private Sub txtPort_Change() Winsock1.RemotePort = txtPort.Text Winsock1.LocalPort = txtPort.Text Winsock1.Listen End Sub Private Sub Winsock1_Close() Winsock1.Close End Sub Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long) 'IF CONNECTION IS SUCCESS If Winsock1.State <> sckClosed Then Winsock1.Close Winsock1.Accept requestID cmdStart.Enabled = True cmdStop.Enabled = False End Sub Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) Dim strIncoming As String Winsock1.GetData strIncoming, vbString txtCommand.Text = strIncoming Call Interpret(txtCommand.Text) End Sub Private Sub UpdateScore() 'Updates score by printing into the file which avoids the " " 'Refreshes the page Open "C:\IED_Score.html" For Output As #1 Print #1, "IED SCORING" Print #1, "" Print #1, "" Print #1, "Section 07 Score" Print #1, "

Current Score: " & Score & "" Print #1, "

Direct Hits: " & DirectHits & "" Print #1, "

Partial Hits: " & PartialHits & "
" Print #1, "

Last updated at: " & Time & "" Print #1, "" Close #1 tmrWebRefresh.Enabled = True End Sub Private Sub Interpret(instring As String) 'Interprets incoming string If instring = "Receive" Then ReceivedString = True ElseIf instring = "cmdDisconnect" Then Winsock1.SendData ("Receive") Winsock1.Close ElseIf instring = "cmdReset" Then Winsock1.SendData ("Receive") DirectHits = 0 PartialHits = 0 Score = 0 Call UpdateScore Else If instring = "cmdScore: 3" Then Score = Score + 3 DirectHits = DirectHits + 1 txtScore.Text = Score Call UpdateScore Winsock1.SendData ("Receive") ElseIf instring = "cmdScore: 1" Then PartialHits = PartialHits + 1 Score = Score + 1 txtScore.Text = Score Call UpdateScore Winsock1.SendData ("Receive") End If End If End Sub Private Sub Winsock1_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) 'Error in connection Winsock1.Close End Sub