PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
VS 2010 [RESOLVED] Working with serial GPIB. What do these lines mean?-VBForums
Results 1 to 3 of 3

Thread: [RESOLVED] Working with serial GPIB. What do these lines mean?

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2012
    Posts
    49

    Resolved [RESOLVED] Working with serial GPIB. What do these lines mean?

    I'm looking at a sample code by Nationalinstruments about using the GPIB NI488.2 protocol to communication with scopes.
    Run into this part of the code. Can anyone tell me what the " Replace(...).Replace(...)" structure does?

    Code:
       Private Function ReplaceCommonEscapeSequences(ByVal s As String) As String
            Return s.Replace("\n", ControlChars.Lf).Replace("\r", ControlChars.Cr)
        End Function 'ReplaceCommonEscapeSequences
    
        Private Function InsertCommonEscapeSequences(ByVal s As String) As String
            Return s.Replace(ControlChars.Lf, "\n").Replace(ControlChars.Cr, "\r")
        End Function 'InsertCommonEscapeSequences

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,292

    Re: Working with serial GPIB. What do these lines mean?

    It's just calling replace twice. That function can be rewritten as below if that makes it easier to read for you:
    Code:
    Private Function ReplaceCommonEscapeSequences(ByVal s As String) As String
            Dim retStr as string = s.Replace("\n", ControlChars.Lf)   'replace all "\n" with a line feed character
            retStr = retStr.Replace("\r", ControlChars.Cr)               'then replace all "\r" with a cartridge return charactrer.
            Return retStr
        End Function 'ReplaceCommonEscapeSequences
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  3. #3
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,242

    Re: Working with serial GPIB. What do these lines mean?

    Exactly what it says on the tin! Multiple replacements.

    Run this for a practical demonstration.

    VB Code:
    1. Dim s As String = "abcdefghijklmnopqrstuvwxyz"
    2. s = s.Replace("g", "1").Replace("x", "2").Replace("m", "3")
    3. Label1.Text = s

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width