Page 1
Page 2
Page 3
Private Sub ShowData(Term As Control, Data As
String)
Dim TermSize As Long, i
Dim Datax As String
Datax = Data
' Make sure the existing text
'doesn't get too large.
Dim Ptr1 As Long
TermSize = Len(Term.Text)
If Len(Datax) > 0 Then
If Mid(Datax, 1, 4) = Esc_Sequence Then
Datax = Right(Datax, Len(Datax) - 4)
End If
If Asc(Right(Datax, 1)) = 17 Then
Datax = Mid(Datax, 1, Len(Datax) - 1)
idata = ""
End If
End If
If TermSize > 15360 Then
Ptr1 = InStr(4097, Term.Text, vbCrLf)
Term.Text = Mid(Term.Text, Ptr1)
TermSize = Len(Term.Text)
End If
' Point to the end of Term's data.
Term.SelStart = TermSize
' Filter/handle BACKSPACE characters.
Do
i = InStr(Datax, Chr(8))
If i Then
If i = 1 Then
Term.SelStart = TermSize - 1
Term.SelLength = 1
Datax = Mid(Datax, i + 1)
Else
Datax = Mid(Datax, 1, i - 2) _
& Mid(Datax, i + 1)
End If
End If
Loop While i
' Eliminate line feeds.
Do
i = InStr(Datax, Chr(10))
If i Then
Datax = Mid(Datax, 1, i - 1) _
& Mid(Datax, i + 1)
End If
Loop While i
' Make sure all carriage returns have a line
feed.
i = 1
Do
i = InStr(i, Datax, Chr(13))
If i Then
Datax = Mid(Datax, 1, i) _
& Chr(10) & Mid(Datax, i + 1)
i = i + 1
End If
Loop While i
' Add the filtered data to the SelText property.
Term.SelText = Datax
Term.SetFocus
Term.SelStart = Len(Term.Text)
End Sub
Finally, the code behind the disconnect button,
and the WaitCursor routine
Private Sub cmdDisconnect_Click()
winsockTerm.RemotePort = 0
winsockTerm.RemoteHost = ""
winsockTerm.Close
txtTerminal = ""
cmdDisconnect.Enabled = False
cmdConnect.Enabled = True
End Sub
Private Sub WaitCursor(status As Boolean)
Dim hCursor
Dim Lret As Long
If status = True Then
hCursor = LoadCursor(0, 32514) 'IDC_WAIT
Lret = SetCursor(hCursor)
Else
hCursor = LoadCursor(0, 0)
Lret = SetCursor(hCursor)
End If
End Sub
Here it is in all its glory, connected to
a Hewlett-Packard development system in California, connected
through a modem.

So there we have it, an almost fully-fledged
terminal emulator. It doesn't handle escape-sequences and the
like, but hey, nobody's perfect. I have tested this control with
a modem, an ethernet card and an IRDA connection through my Nokia
7110, and it works in all three cases.
If you have been struggling with the Winsock
control, I hope this gives you a few pointers.
Previous Page