Results 1 to 10 of 10

Thread: Just curious!

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Location
    Tampa, FL
    Posts
    7

    Question

    Why would you use Mid$ when parsing a string? I am not sure what the $ does?

  2. #2
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    The $ indicates string. Mid$ only works with strings and Mid also works with other data types. (I'm not sure which others) Therefore, Mid$ is faster.

  3. #3
    Member
    Join Date
    Jul 2000
    Location
    BFE in Oregon
    Posts
    33

    Cool Ah the good ol' days of DOS

    Back in the day, $ used to indicate a string(text) variable in basic, coincidently, you can still use it to declare a string variable.

    The functions are identical in code, the only reason Mid$ is faster is because the variables are explicitly declared as string and therefore don't have to be converted from a variant to whatever which takes that extra few nanoseconds.

  4. #4
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    Here's the whole deal.
    I'm almost sure it's correct, however, do some tests because I sort of "forgot" to
    But the differences are very small, so it only matters if you use very large strings and/or quantities of strings.
    Code:
    ' Fastest:
    Dim A As String
    A = Mid$(MyText, X, Y)
    
    ' Following two are the same speed:
    Dim A As String
    A = Mid(MyText, X, Y) ' This is what I always use! :)
    
    Dim A As Variant
    A = Mid$(MyText, X, Y)
    
    ' Slower:
    Dim A As Variant
    A = Mid(MyText, X, Y)
    
    ' Slowest:
    ' No Option Explicit and no Dim
    A = Mid(MyText, X, Y)

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Hehe yonatan, how do you know it's slower to return variant into a variant - because that's what i've been doing if i use Mid, not Mid$. Well, should do some tests, but not on this comp

    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    I think the poor Mid (the one with no dollars ) puts a string in a variant, which has to convert back to a variant before it goes to the original variant which was supposed to receive the string.

    Is that decipherable?

    Maybe I'm just tired.

  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    eh? convert a variant back to a variant? my thought was that you don't have to convert the variant you get in return but it has to be converted to a string if it's assigned to a string.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  8. #8
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    $ = String
    % = Integer
    & = Long
    ! = Single
    # = Double
    @ = Currency
    (Nothing) = Variant
    
    Shortcuts for declaration of strings
    
    Dim Art$  is the same as Dim Art As String
    Dim intCre% is the same as Dim intCre as Integer
    etc.
    dim Art is the same as Dim Art As Variant
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  9. #9
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    If you don't use Option Explicit in your code all assignments are slower even if you have declared your variables.
    This is because of the fact that VB has to check if the variable is declared or not during run-time. If it's not declared VB create it in the form of a Variant.
    When you use Option Explicit this check isn't necessary during run-time because it's done during the compile.

  10. #10
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    If you go to tools/options/editor in VB and tick off Require variable declaration and then you can't forget to put in option explicit
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

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