Results 1 to 5 of 5

Thread: Old string functions [Resolved]

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    262

    Resolved Old string functions [Resolved]

    Hi,
    have just been looking at a bit of code submitted by Gigemboy to redivert the results from a cmd prompt. I want to use this to check to see if a server is running by pinging it and seeing how many packets were returned.
    Anyway am waffaling a bit, my main questions is how to make this more .net like, eg not using mid and instr.
    Had a quick look at the string class but can't see any equivalants (sure I'm just missing them though)

    VB Code:
    1. Private Function succesfulping(ByVal cmdp As String) As Boolean
    2.         Dim recp As Integer
    3.         Dim pacr As Integer
    4.         recp = InStr(cmdp, "Received") + 11
    5.         Try
    6.             pacr = CInt(Mid(cmdp, recp, 1))
    7.         Catch
    8.             pacr = 0
    9.         End Try
    10.  
    11.         Select Case pacr
    12.  
    13.             Case 0
    14.                 succesfulping = False
    15.             Case 1
    16.                 succesfulping = False
    17.             Case 2
    18.                 succesfulping = False
    19.             Case 4
    20.                 succesfulping = True
    21.             Case Else
    22.                 succesfulping = False
    23.         End Select
    24.  
    25.     End Function
    Last edited by Oliver1; Mar 20th, 2006 at 11:44 AM. Reason: Resolved

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Old string functions

    .Substring

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    262

    Re: Old string functions

    Thanks just need an instr replacement now.

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Old string functions

    Whoopsies, I missed that

    InStr equates to .IndexOf().

  5. #5
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    710

    Re: Old string functions [Resolved]

    Our Clear VB source code formatter produces:
    ...
    recp = (cmdp.IndexOf("Received", 0) + 1) + 11
    Try
    pacr = CInt(cmdp.Substring(recp - 1, 1))
    Catch
    pacr = 0
    End Try
    ...
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com

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