Click to See Complete Forum and Search --> : Do Until Loop Problem


bryan822
June 12th, 2009, 03:46 PM
I have the following code in Visual Basic 2005.
OutputStringB is declared as a string.


Do Until ReadIP9B = True
Dim RemoteIpEndPoint9B As New IPEndPoint(IPAddress.Any, 0)
Dim receiveBytes9B As [Byte]() = udpClient.Receive(RemoteIpEndPoint9B)
Dim returnDataB As String = Encoding.Default.GetString(receiveBytes9B)
Dim MyStringB As String = returnDataB
Dim TmpStringB As String = ""
Dim HexStringB As String = ""
Dim OutputStringB As String = ""
Dim XB As Integer
For XB = 0 To MyStringB.Length - 1
HexStringB = Asc(MyStringB.Substring(XB, 1))
TmpStringB = Hex(HexStringB).ToString.PadLeft(2, "0")
OutputStringB = OutputStringB & TmpStringB
OutputLengthB = OutputStringB.Length
Next
If OutputStringB.StartsWith("70000000010013000B01020000000601") Or OutputStringB.StartsWith("7000000001000C000C01") Then
ReadIP9B = True
Else
ReadIP9B = False
End If
Loop


The information I need out of this code is OutputStringB. When I put a break point in the loop and read OutputStringB before the loop is over I can get the information I want out of it. The problem is I need to use the OutputStringB value outside of the loop. After the loop ends it is clearing out OutputStringB and making it Nothing for some reason. Can anybody tell me why?

sotoasty
June 12th, 2009, 04:22 PM
Move the DIM OutputStringB as string out of the Loop. (Before the do until).

Then in the loop, set OutputStringB = "" just before the For Next Loop