Difference between Mid and Mid$


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: Difference between Mid and Mid$

  1. #1
    Amuthan Perez Guest

    Difference between Mid and Mid$


    Is there any difference between Mid and Mid$ apart from support for backward
    compatibility?
    Can anyone help on this.
    Thanks in advance.
    Regards,
    Perez.

  2. #2
    Greg Silvano - codehound.com Guest

    Re: Difference between Mid and Mid$

    Yes. Mid returns a variant, while Mid$ returns a string. You'll get the
    same data back, but Mid$ will execute faster. Same goes for Left$, Right$,
    etc.

    --
    Regards,

    Gregory Silvano
    http://www.codehound.com
    Free Internet Search Engine for VB Developers

    "Amuthan Perez" <amuthan_perez@yahoo.com> wrote in message
    news:3948d16a@news.devx.com...
    >
    > Is there any difference between Mid and Mid$ apart from support for

    backward
    > compatibility?
    > Can anyone help on this.
    > Thanks in advance.
    > Regards,
    > Perez.




  3. #3
    Rick Rothstein Guest

    Re: Difference between Mid and Mid$

    Mid$ is supposed to return a String whereas Mid is supposed to return a
    Variant with a subtype of String. Supposedly, Mid$ is faster if assigning
    its results directly to a String variable. If you are going to use the
    numeric value of a number in String form, for example

    Mid("Here is 43 somethings", 9, 2)

    in a calculation, then Mid is probably faster.

    Rick


    "Amuthan Perez" <amuthan_perez@yahoo.com> wrote in message
    news:3948d16a@news.devx.com...
    >
    > Is there any difference between Mid and Mid$ apart from support for

    backward
    > compatibility?
    > Can anyone help on this.
    > Thanks in advance.
    > Regards,
    > Perez.




  4. #4
    Joel Ryan Guest

    Re: Difference between Mid and Mid$

    I ran a quick test and the performance of mid$ over mid when assigning the
    return value to a string variable seems to be nearly double. (Ex. what would
    take 4 seconds using mid would take 2 seconds using mid$). Unfortunately the
    IDE crashed before I could save the code I wrote or I would post it.
    -- Joel

    Amuthan Perez wrote:

    > Is there any difference between Mid and Mid$ apart from support for backward
    > compatibility?
    > Can anyone help on this.
    > Thanks in advance.
    > Regards,
    > Perez.



  5. #5
    Jim Pragit Guest

    Re: Difference between Mid and Mid$


    I ran a benchmark. Using VB's default compilation settings
    (native code, optimized for fast code, all advanced
    optimizations turned off), Mid$ is over 100% faster
    than Mid when assigning to a string variable:

    'Mid
    Dim s As String
    For x = 1 To mlngIterations
    s = Mid("Here is 43 somethings", 9, 2)
    Next x

    'Mid$
    Dim s As String
    For x = 1 To mlngIterations
    s = Mid$("Here is 43 somethings", 9, 2)
    Next x

    Results (1,000,000 Iterations)
    Mid = 2.29 seconds
    Mid$ = 1.60 seconds

    I used the timeGetTime API (winmm.dll).

    - Jim

    "Rick Rothstein" <rick_newsgroup@email.com> wrote:
    >Mid$ is supposed to return a String whereas Mid is supposed to return a
    >Variant with a subtype of String. Supposedly, Mid$ is faster if assigning
    >its results directly to a String variable. If you are going to use the
    >numeric value of a number in String form, for example
    >
    > Mid("Here is 43 somethings", 9, 2)
    >
    >in a calculation, then Mid is probably faster.
    >
    >Rick
    >
    >
    >"Amuthan Perez" <amuthan_perez@yahoo.com> wrote in message
    >news:3948d16a@news.devx.com...
    >>
    >> Is there any difference between Mid and Mid$ apart from support for

    >backward
    >> compatibility?
    >> Can anyone help on this.
    >> Thanks in advance.
    >> Regards,
    >> Perez.

    >
    >



  6. #6
    Michael Culley Guest

    Re: Difference between Mid and Mid$


    Mid$ is over 100% faster

    >Mid = 2.29 seconds
    >Mid$ = 1.60 seconds


    This is 43% faster

    Sorry, just being picky

    Another use for Mid is when you expect that the value could be a null. Mid
    will return a null, but mid$ will return an error.

    Michael Culley


    "Jim Pragit" <emunews@msn.com> wrote:
    >
    >I ran a benchmark. Using VB's default compilation settings
    >(native code, optimized for fast code, all advanced
    >optimizations turned off), Mid$ is over 100% faster
    >than Mid when assigning to a string variable:
    >
    > 'Mid
    > Dim s As String
    > For x = 1 To mlngIterations
    > s = Mid("Here is 43 somethings", 9, 2)
    > Next x
    >
    > 'Mid$
    > Dim s As String
    > For x = 1 To mlngIterations
    > s = Mid$("Here is 43 somethings", 9, 2)
    > Next x
    >
    >Results (1,000,000 Iterations)
    >Mid = 2.29 seconds
    >Mid$ = 1.60 seconds
    >
    >I used the timeGetTime API (winmm.dll).
    >
    >- Jim
    >
    >"Rick Rothstein" <rick_newsgroup@email.com> wrote:
    >>Mid$ is supposed to return a String whereas Mid is supposed to return a
    >>Variant with a subtype of String. Supposedly, Mid$ is faster if assigning
    >>its results directly to a String variable. If you are going to use the
    >>numeric value of a number in String form, for example
    >>
    >> Mid("Here is 43 somethings", 9, 2)
    >>
    >>in a calculation, then Mid is probably faster.
    >>
    >>Rick
    >>
    >>
    >>"Amuthan Perez" <amuthan_perez@yahoo.com> wrote in message
    >>news:3948d16a@news.devx.com...
    >>>
    >>> Is there any difference between Mid and Mid$ apart from support for

    >>backward
    >>> compatibility?
    >>> Can anyone help on this.
    >>> Thanks in advance.
    >>> Regards,
    >>> Perez.

    >>
    >>

    >



  7. #7
    Jim Pragit Guest

    Re: Difference between Mid and Mid$


    I'm not at the same computer anymore, but I'm pretty sure 1.60 was a typo.
    It should be 1.06.

    - Jim

    "Michael Culley" <m_culley@one.net.au> wrote:
    >
    >Mid$ is over 100% faster
    >
    >>Mid = 2.29 seconds
    >>Mid$ = 1.60 seconds

    >
    >This is 43% faster
    >
    >Sorry, just being picky
    >
    >Another use for Mid is when you expect that the value could be a null. Mid
    >will return a null, but mid$ will return an error.
    >
    >Michael Culley
    >
    >
    >"Jim Pragit" <emunews@msn.com> wrote:
    >>
    >>I ran a benchmark. Using VB's default compilation settings
    >>(native code, optimized for fast code, all advanced
    >>optimizations turned off), Mid$ is over 100% faster
    >>than Mid when assigning to a string variable:
    >>
    >> 'Mid
    >> Dim s As String
    >> For x = 1 To mlngIterations
    >> s = Mid("Here is 43 somethings", 9, 2)
    >> Next x
    >>
    >> 'Mid$
    >> Dim s As String
    >> For x = 1 To mlngIterations
    >> s = Mid$("Here is 43 somethings", 9, 2)
    >> Next x
    >>
    >>Results (1,000,000 Iterations)
    >>Mid = 2.29 seconds
    >>Mid$ = 1.60 seconds
    >>
    >>I used the timeGetTime API (winmm.dll).
    >>
    >>- Jim
    >>
    >>"Rick Rothstein" <rick_newsgroup@email.com> wrote:
    >>>Mid$ is supposed to return a String whereas Mid is supposed to return

    a
    >>>Variant with a subtype of String. Supposedly, Mid$ is faster if assigning
    >>>its results directly to a String variable. If you are going to use the
    >>>numeric value of a number in String form, for example
    >>>
    >>> Mid("Here is 43 somethings", 9, 2)
    >>>
    >>>in a calculation, then Mid is probably faster.
    >>>
    >>>Rick
    >>>
    >>>
    >>>"Amuthan Perez" <amuthan_perez@yahoo.com> wrote in message
    >>>news:3948d16a@news.devx.com...
    >>>>
    >>>> Is there any difference between Mid and Mid$ apart from support for
    >>>backward
    >>>> compatibility?



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center