Results 1 to 9 of 9

Thread: Rich Text Box to Variable

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2011
    Posts
    42

    Exclamation 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.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: Rich Text Box to Variable

    it'll be easier to intercept it before it gets in to the rtb

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: Rich Text Box to Variable

    here's an example using regex:

    vb Code:
    1. Dim testStr As String = "<T1234>" & Environment.NewLine & "<V5678>"
    2.  
    3. Dim rx As New Regex("(?<=\<T).+?(?=\>)")
    4. MsgBox(String.Format("T{0}", rx.Match(testStr).Value))
    5.  
    6. rx = New Regex("(?<=\<V).+?(?=\>)")
    7. MsgBox(String.Format("V{0}", rx.Match(testStr).Value))

    don't forget to import regex:

    vb Code:
    1. Imports System.Text.RegularExpressions

  4. #4

    Thread Starter
    Member
    Join Date
    Aug 2011
    Posts
    42

    Re: Rich Text Box to Variable

    Quote Originally Posted by .paul. View Post
    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.

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: Rich Text Box to Variable

    yes regex is installed. to use my code you need to import it as i recommended

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: Rich Text Box to Variable

    this is where you put imports statements. at the top line of your form or class:

    vb Code:
    1. Imports System.Text.RegularExpressions
    2.  
    3. Public Class Form1
    4.  
    5.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    6.  
    7.     End Sub
    8.  
    9. End Class

  7. #7

    Thread Starter
    Member
    Join Date
    Aug 2011
    Posts
    42

    Re: Rich Text Box to Variable

    vb Code:
    1. Here is how my message are received, how do I intercept them?
    2.  
    3.     Private Sub appendText1(ByRef incomingMessage1 As String)
    4.         rtbR1.Clear()
    5.         'Delegates.RichTextBoxes.appendText(Me, rtbDebug, incomingMessage1)
    6.         Delegates.RichTextBoxes.appendText(Me, rtbR1, incomingMessage1)
    7.  
    8.         If frmMain.lbStations.SelectedIndex = 1 Then
    9.             Delegates.RichTextBoxes.appendText(frmMain, frmMain.rtbMain, incomingMessage1)
    10.         End If
    11.  
    12.     End Sub

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: Rich Text Box to Variable

    it looks like incomingMessage1 is the text in 2 parts

  9. #9

    Thread Starter
    Member
    Join Date
    Aug 2011
    Posts
    42

    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:
    1. Try
    2.             AddHandler readerSock1.IncomingData, AddressOf appendText1
    3.  
    4.             readerSock1.Connect(arrIP.Item(0), arrPort.Item(0))
    5.  
    6.             If readerSock1.isConnected Then
    7.                 rtbDebug.AppendText("Reader 1 Connected" & vbCrLf)
    8.             Else
    9.                 rtbDebug.AppendText("Reader 1 NOT Connected" & vbCrLf)
    10.             End If
    11.         Catch ex As Exception
    12.             rtbDebug.AppendText(ex.Message)
    13.         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
  •  



Click Here to Expand Forum to Full Width