Results 1 to 21 of 21

Thread: Left or Left$

  1. #1

    Thread Starter
    Hyperactive Member Juan Carlos Rey's Avatar
    Join Date
    Aug 1999
    Location
    Mendoza, Argentina
    Posts
    301

    Post

    I think both XxEvilxX and wossname are pouring water outside the flower vase!
    "Left$" is a function in Q Basic to retrieve a portion of a string counting from left side, and "Rigth$" is the like for right side.
    In VB they are "Left" and "Right", respectively.
    Right$ and Left$ still work only for the sake of compatibility but they are not guaranteed to work in VB7 or future versions.

  2. #2
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923

    Post

    Hey guys

    What's the difference between Left and Left$ or Right and Right$?

    Help doesn't explain very well.

    Thanks

    Regards,

    ------------------
    - Chris
    [email protected]
    If it ain't broke - don't fix it

  3. #3
    Addicted Member
    Join Date
    Jul 1999
    Posts
    219

    Post

    Well Hey The $ After Right or left Just Means That Left$ = String Cuase $ means string and The Same As Right$

  4. #4
    Guest

    Post

    OK, im going to set a trend now and build a coherent sentence...

    always use Left$ or right$ when you are using strings, because it is about 60% faster than without the $. this is to do with the memory allocation routines that Windows uses for strings. Trust me. plus $ does bad things to numbers in certain circumstances!

  5. #5
    New Member
    Join Date
    Jan 2000
    Posts
    6

    Post

    Sorry, Juan Carlos, XxEvilxX and wossname are right. Left$ and Right$ work at least twice as fast, especially when doing work with arrays and collections, than your Left and Right functions. There are also other functions that most of us use that have a similar $ counterpart function that you can use with strings.

    Granted, both were old QBasic functions, but the reason they were held over is because of their speed. I don't think they would have kept them through 6 versions of a different language for no apparent reason, do you?

    Rad Brad

  6. #6
    Hyperactive Member Al Smith's Avatar
    Join Date
    May 1999
    Location
    Marcellus, MI. USA
    Posts
    330

    Post

    Oh No!
    I assume the same is true for mid$ and right$. I've now got a ton of code in several programs that I now have to edit.
    Sometimes ignorance IS bliss.
    Al.


    ------------------
    A computer is a tool, not a toy.
    <A HREF="mailto:[email protected]
    [email protected]">[email protected]
    [email protected]</A>


  7. #7
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    I can't find any documentation on the differences between Left and Left$....how do you guys know that it is faster?

  8. #8
    Guest

    Post

    I can find much of a difference - left is faster to type then left$ so I just use that!


  9. #9

    Thread Starter
    Hyperactive Member Juan Carlos Rey's Avatar
    Join Date
    Aug 1999
    Location
    Mendoza, Argentina
    Posts
    301

    Post

    Rad_Brad:

    If you read carefully the XxEvilxX answer, at least as I interpret it, he is talking about data types, as "Porky" being an Integer and "Porky$" a String.
    With wossname there are doubts left, but I assume the same, he is talking about data types.

    In my VB 4.0 Help I found something interesting:

    "Algunas funciones tienen dos versiones, una que devuelve un tipo de dato Variant y otra que devuelve un tipo de dato String. Las versiones de variante tienden a ser las más convenientes ya que los variantes manejan las conversiones entre los diferentes tipos de dato automáticamente."

    And this means approximately:

    "Some functions have two versions, one returns a Variant data type, the other a String one. Variants tend to be more appropriate because they manage automatically the conversion between different data types"

    Well, it is true that working with Variants is slower than with Strings. That can be a clue for the speed increase.

    And to Al Smith: yes, you are right, the same is for mid$ and others:

    "Las siguientes funciones devuelven valores en una variable de tipo String cuando se agrega un signo de dólar ($) al nombre de la función. Estas funciones tienen el mismo uso y sintaxis que sus equivalentes de variante sin el signo de dólar:
    Chr$ - ChrB$ - CurDir$ - Date$ - Dir$ - Error$ - Format$ - Hex$ - Input$ - InputB$ - LCase$ - Left$ - LeftB$ - Mid$ - MidB$ - Oct$ - Right$ - RightB$ - RTrim$ - Space$ - Str$ - String$ - Time$ - Trim$ - UCase$"

    I leave the translation to you as a home work.

    Well, just to test the speed, I tried the following code:

    -------
    Private Sub Command1_Click()
    Text1.Text = "Who and see to sake ago in lost pant alone east"
    StartTime = Timer
    For i = 1 To 5000
    Text2.Text = Left$(Text1.Text, 20)
    Text3.Text = Right$(Text1.Text, 20)
    Next
    Text4.Text = Timer - StartTime
    End Sub
    -------

    Run it three ore four times, record the times (in the order of 6.4 seconds in my Pentium S 166 MHz)

    Changed Left$ to Left and Right$ to Right, repeated the test, and obtained the same times. Perhaps there are better routines to test speed, but for me it's enough.



    [This message has been edited by Juan Carlos Rey (edited 01-16-2000).]

  10. #10
    Hyperactive Member Al Smith's Avatar
    Join Date
    May 1999
    Location
    Marcellus, MI. USA
    Posts
    330

    Post

    Rough translation?

    The following functions return values in a variable of string type when a dollar sign is attached to them. These functions have the same use and syntax as their equivelents without the dollar sign.

    Al.


    Al.


    ------------------
    A computer is a tool, not a toy.
    <A HREF="mailto:[email protected]
    [email protected]">[email protected]
    [email protected]</A>


  11. #11

    Thread Starter
    Hyperactive Member Juan Carlos Rey's Avatar
    Join Date
    Aug 1999
    Location
    Mendoza, Argentina
    Posts
    301

    Post

    I dare to correct Al a litlle:

    "These functions have the same use and syntax as their Variant equivalents without the dollar sign"

  12. #12
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923

    Post

    Have I started an aurgument? Does this mean no-one really knows the difference? well, just incase Left$/Right$ is quicker, I'm going to replace all instances of Left or Right in my programs.

    Juan, I appologise for being typically English, but is that Spanish I see...?

    Thanks all

    kind regards,



    ------------------
    - Chris
    [email protected]
    If it ain't broke - don't fix it

  13. #13
    Hyperactive Member
    Join Date
    Jan 1999
    Location
    Rotterdam, Netherlands
    Posts
    386

    Post

    The answer is given...
    The $-versions of the function return a string (Left$) while the other (Left) is returning a variant, so a conversion is needed when you assign the return value to a string. (but then, Variants are always slower and consume more memory then the 'real' type variables)
    Wonder though when you start to notice the difference in speed.

  14. #14

    Thread Starter
    Hyperactive Member Juan Carlos Rey's Avatar
    Join Date
    Aug 1999
    Location
    Mendoza, Argentina
    Posts
    301

    Post

    chrisjk:

    1- yes, it seems you started an argument...

    2- today I opened HELP in my VB 6 and couldn't find any reference to "left$", all links pointed toward "left" and nothing was told about variants, strings, etc.

    3- I wouldn't care to replace Left with Left$ as I couldn't see any speed improvement at all (you'll see in my code each conversion was done 5000 times!)

    4- If that argentine dialect could be called Spanish...
    I have Spanish version of VB 4, I just copied/pasted in sake of precision. My translation could be not too accurate.

    regards

    [This message has been edited by Juan Carlos Rey (edited 01-17-2000).]

  15. #15
    Guest

    Post

    just because you cant find something in a help file doesnt qualify you to discount other peoples knowledge of something.

    if you use it in very heavy string manipulations app's then you will find a noticable difference in the amount of time between $ and non-$ functions, can be as much as 7 minutes over an hour of hard calculations. I have used it when manipulating names and addresses from CSV files containing hundreds of thousands of people's details. I know what i am talking about

  16. #16
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    Post

    I compared the two in a loop of 50000, and noticed the $ version is about 1 % faster then the other one. Not enough to spend time changing my code.

  17. #17
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    Post

    I have to correct myselve. I used the code of Juan Carlos, but this appears not to be a correct test. Inside the loop, two properties are set, and this takes 99 % of the time. I changed assigning the result to a property to assigning the result to a variable, and there was a dramatic change.
    The $ version is 63.4 % faster then the other one, so there is a good reason to use it if used a lot.

  18. #18

    Thread Starter
    Hyperactive Member Juan Carlos Rey's Avatar
    Join Date
    Aug 1999
    Location
    Mendoza, Argentina
    Posts
    301

    Post

    Oh, wossname, I am not trying to argue!
    I didn't mean to disqualify nobody, I am still an apprentice. If you see my previous post, in VB 4.0 I found the difference, they said "Left$" returns a string and "Left" a Variant, but in VB 6 they did not mention a word about!
    Please don't Blame.Me!
    Frans C, can I have a look at your code? Because your results are consistent with wossname 60 % faster assertion!

  19. #19
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    Juan Carlos Rey. When you ran your test program and got the same times, could the reason for that be because you used a timer?

    I couldn't quite follow your code through, it looked like there were some things missing. Anyway, just a thought.

    ------------------
    Ryan

  20. #20
    Registered User
    Join Date
    Apr 1999
    Location
    Brazil
    Posts
    144

    Post

    wossname

    You are sure, the help doesn't metter, 'cause Microsoft could forget to include theese functions in VB help (or they don't care - that is worst).

    I know that functions with $ is faster since VB4 (the first version that I learn)!

    Jefferson

  21. #21
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    I used this code, only changing the Left to Left$, and got less than a 1% performance increase by using Left$....

    Code:
    Private Declare Function GetTickCount Lib "kernel32" () As Long
    
    Private Sub Form_Load()
        
        Dim strString As String
        Dim I As Long
        Dim lngBegin As Long
        Dim lngEnd As Long
        Dim strTemp As String
        
        lngBegin = GetTickCount
        
        For I = 1 To 10000
            
            strString = strString & "asdf"
            
        Next I
        
        For I = 1 To Len(strString)
            strTemp = Left$(strString, I)
        Next I
        
        lngEnd = GetTickCount
        
        MsgBox lngEnd - lngBegin
        End
    End Sub

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