Array set only with breakpoints

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am running into a problem with the below code while trying to
gather a listing of files on a server. When I run the code without
breakpoints, it only collects the first file and nothing else. When
I set a breakpoint at the Do statement, and step through the code,
variable 'mess' contains all the files in the directory.

Do While (True)
m_aBuffer.Clear(m_aBuffer, 0, m_aBuffer.Length)
bytes = cSocket.Receive(m_aBuffer, m_aBuffer.Length, 0)
m_sMes = ASCII.GetString(m_aBuffer, 0, bytes)

If (bytes < m_aBuffer.Length) Then
Exit Do
End If

Loop
mess = m_sMes.Split(seperator)
cSocket.Close()

Thanks for any help in advance,
JT Johnston
 
Hi,

You overwrite m_sMes everytime you run the loop. Try this instead.

m_sMes &= ASCII.GetString(m_aBuffer, 0, bytes)

Ken
 
Thanks for the response! I changed the code, but it still only registers the
last file in the directory. I also tried moving the line:

m_aBuffer.Clear(m_aBuffer, 0, m_aBuffer.Length)

to before the Do Loop, but nothing.

Thanks again for your response.
JT Johnston
 
Ken, Thanks again for answering back. Sorry I didn't get right back to you.
I wanted to let you know what was happening, and the changes I made to the
code to fix the problem. I was using the right command, but cSocket.receive
was not receiving all the data from the server, so the following is the new
code calls the cSocket.receive additional times.

New Code:

Do While (True)
m_aBuffer.Clear(m_aBuffer, 0, m_aBuffer.Length)
bytes = cSocket.Receive(m_aBuffer, m_aBuffer.Length, 0)
m_sMes += ASCII.GetString(m_aBuffer, 0, bytes)
If (bytes <= 0) Then
Exit Do
End If
Loop

Thanks again for your help, and Happy Holidays!
JT Johnston
 
Back
Top