how to show control character when using comm port

E

Thread Starter

etherny

hello everybody...

anyone can tell me how to display the control character (ASCII 0-31) e.g.: <STX>,<ETX>... in the data that read from comm port using visual basic 6.0? Can show me some source code to solve this kind of problem?

Your help is appreciated... THANKS
 
<p>The following sample will take a string "a$" and substitute another string for all ASCII control characters (0 - 31). The resulting string is stored in b$. This should work for all ASCII codes through 127. Extended codes 128 through 255 could be handled in a similar fashion if desired.
<pre>
Dim symbol$(31)
symbol$(0) = "<NUL>"
symbol$(1) = "<SOH>"
symbol$(2) = "<STX>"
' include symbol for 3 throught 30
symbol$(31) = "<US>"
'line containing mixed printable ASCII and control characters
a$ = "ABC" + Chr$(2) + "DEF" + Chr$(0) + "G" + Chr$(31) + "H"
'initialize output line containing formatted string
b$ = ""
'loop through the input line and either copy the character or
'insert the appropriate string
For i = 1 To Len(a$)
If (Asc(Mid$(a$, i, 1)) <= 31) Then
b$ = b$ + symbol$(Asc(Mid$(a$, i, 1)))
Else
b$ = b$ + Mid(a$, i, 1)
End If
Next i
'At this point b$ contains the modified string and
'a$ is still intact
Text1.Text = b$
</pre>
<p>Sealevel Systems (http://www.sealevel.com) includes code samples for C++ and VB on the CD that ships with their products.
 
Top