|
-
Sep 7th, 2011, 02:33 PM
#1
Thread Starter
Member
Rich Text Box to Variable
I have incoming messages from a socket client going into a rich text box. Is there a way to find a part of a string and then extract x amount of characters out of that line into a variable?
Example:
I send a <T> command to the unit
I send a <V> command to the unit
the unit responds into the RTB
<TXXXX>
<VXXXX>
(XXXX could be any combination of numbers)
I need to get the TXXXX and put it in 1 variable and put the VXXXX into another variable.
-
Sep 7th, 2011, 02:40 PM
#2
Re: Rich Text Box to Variable
it'll be easier to intercept it before it gets in to the rtb
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 7th, 2011, 02:47 PM
#3
Re: Rich Text Box to Variable
here's an example using regex:
vb Code:
Dim testStr As String = "<T1234>" & Environment.NewLine & "<V5678>"
Dim rx As New Regex("(?<=\<T).+?(?=\>)")
MsgBox(String.Format("T{0}", rx.Match(testStr).Value))
rx = New Regex("(?<=\<V).+?(?=\>)")
MsgBox(String.Format("V{0}", rx.Match(testStr).Value))
don't forget to import regex:
vb Code:
Imports System.Text.RegularExpressions
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 7th, 2011, 03:00 PM
#4
Thread Starter
Member
Re: Rich Text Box to Variable
 Originally Posted by .paul.
it'll be easier to intercept it before it gets in to the rtb
That would be so much easier, I do not like RTB. RegEx is already installed with VS2008 correct? I am new to VS2008.
-
Sep 7th, 2011, 03:02 PM
#5
Re: Rich Text Box to Variable
yes regex is installed. to use my code you need to import it as i recommended
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 7th, 2011, 03:04 PM
#6
Re: Rich Text Box to Variable
this is where you put imports statements. at the top line of your form or class:
vb Code:
Imports System.Text.RegularExpressions
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 7th, 2011, 03:08 PM
#7
Thread Starter
Member
Re: Rich Text Box to Variable
vb Code:
Here is how my message are received, how do I intercept them?
Private Sub appendText1(ByRef incomingMessage1 As String)
rtbR1.Clear()
'Delegates.RichTextBoxes.appendText(Me, rtbDebug, incomingMessage1)
Delegates.RichTextBoxes.appendText(Me, rtbR1, incomingMessage1)
If frmMain.lbStations.SelectedIndex = 1 Then
Delegates.RichTextBoxes.appendText(frmMain, frmMain.rtbMain, incomingMessage1)
End If
End Sub
-
Sep 7th, 2011, 03:29 PM
#8
Re: Rich Text Box to Variable
it looks like incomingMessage1 is the text in 2 parts
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 7th, 2011, 03:41 PM
#9
Thread Starter
Member
Re: Rich Text Box to Variable
From what I understand from the code I manipulated, I have to use the delegates command to be able to see the message coming in and RTB is the only option I can see. I could be wrong and I hope I am... Here is the code I use to connect, you can see where I define it.
vb Code:
Try
AddHandler readerSock1.IncomingData, AddressOf appendText1
readerSock1.Connect(arrIP.Item(0), arrPort.Item(0))
If readerSock1.isConnected Then
rtbDebug.AppendText("Reader 1 Connected" & vbCrLf)
Else
rtbDebug.AppendText("Reader 1 NOT Connected" & vbCrLf)
End If
Catch ex As Exception
rtbDebug.AppendText(ex.Message)
End Try
The addressOf command I am not to familiar with. Maybe there is a better command?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|