Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Telnet App (String handling) Please Help 1

Status
Not open for further replies.

rjr9999

Programmer
Apr 7, 2001
183
US
Ok, I'm able now to connect and accept data from and send data to the telnet session. Now there's some more problems. I ran across a MUD, which outputs escape characters for ANSI color. What i'd like to do is either not display them, or change the font color upon seeing them. The problem here is that the pushes all output in buffers...meaning one string is between 1 and 10000 characters. Now, I'm a C programmer by nature ;), and In C it would be easy to just read the string character by character, stick it in an array, and then output only the characters I want. But how am I going to do this in Basic? Is there a way to break a string down character by character? Please help.

Rob
 
This may point you in the right direction...

Dim bybuffer() As Byte

bybuffer = StrConv("Hello World", vbFromUnicode)

byBuffer is now an array of ascii characters
 
ok, now how do I check the byte mode to be null? eg.

do while bybuffer <> &quot;&quot; is a type mismatch
 
The byte array contains numeric ascii values. Null = 0, Space = 32, A = 65, etc, etc
 
ok, now i got it printing text, but it get's so far and then says &quot;sub script out of range&quot; here's the function...

Private Sub dispData(strData As String)
Dim outBuffer() As Byte
Dim strOut As String
looper = 1
looper2 = 1
outBuffer = StrConv(strData, vbFromUnicode)
Do While outBuffer(looper) <> 0
If (Chr(outBuffer(looper)) = &quot;&quot;) And (Chr(outBuffer(looper + 1)) = &quot;[&quot;) And (Chr(outBuffer(looper + 2)) = &quot;3&quot;) And (Chr(outBuffer(looper + 3)) = &quot;6&quot;) And (Chr(outBuffer(looper + 4)) = &quot;m&quot;) Then
Text1.ForeColor = vbBlue
End If
If (Chr(outBuffer(looper)) = &quot;&quot;) Then
looper = looper + 5
End If
strOut = Chr(outBuffer(looper))
Text1.Text = Text1.Text + strOut
looper = looper + 1
Loop
End Sub


This line is the one the debugger picks up on as being &quot;Subscript out of range&quot;...what am I doing wrong?

If (Chr(outBuffer(looper)) = &quot;&quot;) And (Chr(outBuffer(looper + 1)) = &quot;[&quot;) And (Chr(outBuffer(looper + 2)) = &quot;3&quot;) And (Chr(outBuffer(looper + 3)) = &quot;6&quot;) And (Chr(outBuffer(looper + 4)) = &quot;m&quot;) Then
 
The byte array is zero based and your looper variable starts at 1 so you are skipping the 1st byte and, you may have to add a Null value to the end of your string so that your loop will exit before it goes beyond the subscript range...

outBuffer = StrConv(strData & chr$(0), vbFromUnicode)

 
ok, i reste the array to start at 0, and i added the null character at the end. It ended up printing one more letter from the output, and still crashing at the same spot...perhaps my &quot;string&quot; is too large? What's the max size of an array in VB? Thanks again for this help.
 
When it bombs, what is the value of looper? How large is your byte array?

Try this..

Put a break point on the line

Do While outBuffer(looper) <> 0

When it breaks, right-click on the outBuffer variable which is in the line before your breakpoint

select add watch. Watch Type should be Watch Expression. click OK. Now you can look at the values in the byte array and maybe see why it is bombing.



 
Got it! For some reason, VB does not like makeing a check to outBuffer(looper) = &quot;whatever&quot; if that iteration doesn't exist...bad C habbit, where as if it will check it, and if it doesn't exist, then obviously it's not &quot;whatever&quot; :p...i fixed this by adding 5 extra null spaces to the array, you know, for error checking ;P...Thanks again! On to the next question...i'll post it as a new thread.

Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top