read/select items from textbox

mirzao

Active member
Joined
Nov 10, 2005
Messages
44
Location
Malaysia
Programming Experience
Beginner
Hi ,

I 'm writing an application to communicate with a serial device and used the RS232 class from codeworks.it. I got a reply like this :

strs
305 40A

FLASH0(RAM)>


strs is a command to get the status of the serial device.The code {305} and {40A} tells me a different status (actually, it can gives more than 2 codes in one time). How can I only read/select these code from the textbox?
 
Where does the TextBox come into this? You must have got a string returned to you to put in a TextBox in the first place so why not work with that string? You've assigned it to the Text property of the TextBox so it's still the same string anyway. Having said that, if you have a series of substrings seperated by spces you would use the String.Split method to seperate them:
VB.NET:
Dim substrings As String() = myString.Split(" "c)
 
The reply from the serial device is put into a multiline textbox. The string that I want to extract is in line 2, 5, 8,...etc because the command must be sent many times. Is it possible to do that with string.split method?
 
The TextBox class has a Lines property that is an array of String containing the individual lines in the TextBox. From the numbers you have specified it would seem that you want the second line from every group of three. You could do that something like this:
VB.NET:
'Start at the second line and take every third line from there.
For i As Integer = 1 To myTextBox.Lines.Count - 1 Step 3
    MessageBox.Show(myTextBox.Lines(i))
Next i
 
Sorry for asking your help again. I run your code but it keeps given me the previous line again instead only the line that i want ( before the line 8 pops out, line 2 and 5 popped out again).How can I prevent this?
 
That code will start at the second line and then give you every third line there after. I'm not quite sure what you're saying is the issue but if you just want one specific line then you should just index the Lines property to get that specific line. Also, I mistakenly used Count instead of Length in that code. Count is for collections, not arrays.
 
Thanks for you reply. I really appreciate it.As in my first post, I did mentioned that I tried to communicate with serial device. The status command is sent for many times to two different COM ports and the results are displayed in the textbox. I have extracted the line that contains the code from the textbox . Next, I want to extract each code in a line to categorized them and then compare it to the previous code. Any idea how to do that?

Thanx in advance.
 
Back
Top