Left$ Function, Looping through

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #16
    Originally posted by willakawill
    Yes you can do it this way. The notion that you are now 'speeding things up' by using binary comparison is lost on the fact that you have introduced 2 extra string processes to ensure same case.

    Binary comparison will compare the string byte by byte numerically so it is case sensitive. Text comparison is not case sensitive and has a processing overhead to cover that. Setting the 2 strings to upper or lowercase eliminates any speed benefit so you might as well use text comparison. It reads better :)
    I'd have to agree. You're running two string functions to try and implement what might possibly be a slight faster version of statement. In any case, speed seems unlikely to be a major concern, unless you're dealing with huge quantities of data. For simplicity of coding (and readability) it's probably better to use the text compare rather than binary, and drop the extra functions. They make the code very messy.

    Splitting the line may help a little, though. For example...
    Code:
    strGetWords = InStr( _
                        LCase(" " & Text6(0).Text & " "), _
                        LCase(" " & Text1.Text & " "), _
                        vbBinaryCompare)
    (You may notice I dropped the optional position parameter at the start of Instr - that's just the way I prefer it. I was also playing around a little with the positioning of the LCase function for readability.)

    Comment

    • Dököll
      Recognized Expert Top Contributor
      • Nov 2006
      • 2379

      #17
      Groovy, thank heavens for copies. Fantastic, will keep the good copy then...
      Where are these happy faces coming from anyway?

      In a bit!

      Comment

      • willakawill
        Top Contributor
        • Oct 2006
        • 1646

        #18
        Originally posted by Dököll
        Did you, WillAkaWill, by any chance, check out Aivosto? Do you think they're solid in they optimiztion techniques. I should really be careful wat I am reading.
        Any site that tells you to use vbBinaryCompare because it is faster is not worth me spending my time reading. There are a lot of treasure troves out there and a lot of nonsense. This particular recommendation belongs to the latter group.

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #19
          Originally posted by Dököll
          Groovy, thank heavens for copies. Fantastic, will keep the good copy then...
          Where are these happy faces coming from anyway?
          Have a look here.

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #20
            Originally posted by willakawill
            Any site that tells you to use vbBinaryCompare because it is faster is not worth me spending my time reading. There are a lot of treasure troves out there and a lot of nonsense. This particular recommendation belongs to the latter group.
            It depends a bit on how they "sell" it, I'd say. It certainly shouldn't be pushed as a dogmatic "use binary it's faster", because if there is any performance difference at all, it would almost always be outweighed by functionality considerations.

            (Note, the following example is just made up to illustrate the point - it may or may not be true.)

            It still might make sense to say something like "if your strings only contain numeric digits, or punctuation marks, then using vbBinaryCompare executes a little faster".

            Comment

            • willakawill
              Top Contributor
              • Oct 2006
              • 1646

              #21
              Originally posted by Killer42
              It depends a bit on how they "sell" it, I'd say. It certainly shouldn't be pushed as a dogmatic "use binary it's faster", because if there is any performance difference at all, it would almost always be outweighed by functionality considerations.

              (Note, the following example is just made up to illustrate the point - it may or may not be true.)

              It still might make sense to say something like "if your strings only contain numeric digits, or punctuation marks, then using vbBinaryCompare executes a little faster".
              We can let them off the hook just this once. this is from the website:

              "If you need a case-insensitive StrComp(), use LCase$ to do it, especially if it's enough on one parameter only:
              Code:
              StrComp(Text1$, "abc", vbTextCompare)           ' Slower
              StrComp(LCase$(Text1$), "abc", vbBinaryCompare) ' Faster
              In the following case, the two calls to LCase$ remove the performance gain you got above.
              Code:
              StrComp(LCase$(Text1$), LCase$(Text2$), vbBinaryCompare)

              Comment

              • Dököll
                Recognized Expert Top Contributor
                • Nov 2006
                • 2379

                #22
                Point, again, well taken, Will...

                Been deep into it lately, 80 percent complete by the way. I am using every precausionary measures to ensure my buddy will have less to worry about, in the event large blocks of text are found in the lyrics he hopes to load. I am using LCase sparingly therefore...

                Talk to you real soon!

                Comment

                • Dököll
                  Recognized Expert Top Contributor
                  • Nov 2006
                  • 2379

                  #23
                  Thanks for all your advice here, the both of you. At the risk of confusing myself, and because a newbie should have been told the dos and don'ts of using either method (Text/BinaryCompare), I decided to keep it real, a second opinion seems to count as gold. Thanks much, and by the way, I am actually tilting my head for smilies, for the time being anyway :-)

                  Comment

                  Working...