stuck in a loop please help

afalbusa

New member
Joined
May 26, 2010
Messages
2
Programming Experience
Beginner
Hello I am have a problem getting out of a while loop, i am bringing in ascii code from ports on three diferent machines in to the serial port on a computer, two of the machines give form feed (12) at the end of the printout but one machine does not it only gives out line feed and carriage return (10)(13) is there another way of getting out of this loop, my be to do with the readbuffer being empty, please help

Andy.



Input = serialport1.readchar

While input <>(12)

Dataline =””

While input<>(10)

If input<(32) then

Else

Dataline = dataline & chr (input)

End if

Input = serialport1.readchar

End while

Input = serialport1.readchar

w.writeline (dataline)



End while

Listbox1.items.add (“closing file”)

w.flush() ‘w is the stream writer

w.close()
 
With proper indentation, this is what we have going on.
VB.NET:
Input = serialport1.readchar
While input <>(12)
    dataline = ””
        While input<>(10)
            If input<(32) then
                [B]'just my comment - if there is no THEN why this statement?
[/B]            Else
                Dataline = dataline & chr(input)
            End If
                Input = serialport1.readchar
        End while
    
    Input = serialport1.readchar
    w.writeline (dataline)
End while

Listbox1.items.add (“closing file”)
w.flush() ‘w is the stream writer
w.close()
My question to you is: which loop are you trying to exit?
 
hello Hack thankyou for the reply I am stuck in the first while where it has just left the inner while, what is happening is the ascii code has just given a line feed (10) at the end of the print out so exits the internal loop but becouse this machine does not give me the form feed (12) it will not exit the first loop, I need something that will get me out, I thought I might be able to use something that reads the read buffer at 0 but I can't seem to find anything, this is my first project with VB so my terminology might be mixed up.

thanks again

Andy.
 
You can exit a For/Next loop with an "Exit For"
You can exit a Do While loop with an "Exit Do"

However, there is no "Exit While" to exit a While/Wend loop in VB.

You could, however, use Exit Sub providing you don't have any code after the loop that needs to be executed.
 
VB.NET:
for i = 0 as integer to whatever
 'bla bla
  [B]next[/B]

no, thats not what i mean... thats a "for-next" structure.

lets say for the following
VB.NET:
For i = 0 to 10
   If i <= 8 then
      'blablah
   Else
      'The first time the code comes to here is when i = 9, lets say I want it to go to next i, how do I? instead of just exiting the structure totally, I would like it to proceed to the "next i" without closing the structure with a "next i", got my idea?
   End If
Next i
 
Back
Top