Why oh why???
-
Found this bit of VB/VBA code to be interesting! :D
If (Len(Replace(colourStyle, AP_colourStyle, "")) = 0) then
For some reason it took me a little while to realize that it simply meant:if (Trim$(colourStyle) = Trim$(AP_colourStyle)) then
:-O I could probably leave out the trim$() calls, but I like to make sure there are no pesky extra surronding spaces. -EM -
Found this bit of VB/VBA code to be interesting! :D
If (Len(Replace(colourStyle, AP_colourStyle, "")) = 0) then
For some reason it took me a little while to realize that it simply meant:if (Trim$(colourStyle) = Trim$(AP_colourStyle)) then
:-O I could probably leave out the trim$() calls, but I like to make sure there are no pesky extra surronding spaces. -EM -
Found this bit of VB/VBA code to be interesting! :D
If (Len(Replace(colourStyle, AP_colourStyle, "")) = 0) then
For some reason it took me a little while to realize that it simply meant:if (Trim$(colourStyle) = Trim$(AP_colourStyle)) then
:-O I could probably leave out the trim$() calls, but I like to make sure there are no pesky extra surronding spaces. -EMIncorrect.
Replace()
replaces every instance, so withcolourStyle="APAPAP"
AP_colourStyle="AP"the string would vanish and fire the original
if
, and not yours. :)Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
Not quite the same. What if colourStyle already has a length of 0.
"You get that on the big jobs."
Good catch.
-
Incorrect.
Replace()
replaces every instance, so withcolourStyle="APAPAP"
AP_colourStyle="AP"the string would vanish and fire the original
if
, and not yours. :)Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
Good point.
-
Incorrect.
Replace()
replaces every instance, so withcolourStyle="APAPAP"
AP_colourStyle="AP"the string would vanish and fire the original
if
, and not yours. :)Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
That's a great point and here's my 5. These vars could never have that type of situation due to how they get their data, but the basic premise you point out is correct. Assuming that the 2 vars refer to the same type of data (i.e. a "ColourStyle"), but from 2 different sources, I still don't see why someone would create that line of code. What design instructions would lead someone to use that type of logic? Any ideas, I'm interested to see other's take on this. -EM
-
Not quite the same. What if colourStyle already has a length of 0.
"You get that on the big jobs."
Best catch of the 2 so far! Here's my 5. I hadn't noticed that particular morsel, and it is a possibility given the usage of these vars elsewhere in the code, and how the values get attributed to them. Again fine catch. Kudos! Hmm, does anyone really say "Kudos" anymore??????? :-O -EM
-
That's a great point and here's my 5. These vars could never have that type of situation due to how they get their data, but the basic premise you point out is correct. Assuming that the 2 vars refer to the same type of data (i.e. a "ColourStyle"), but from 2 different sources, I still don't see why someone would create that line of code. What design instructions would lead someone to use that type of logic? Any ideas, I'm interested to see other's take on this. -EM
emartinho wrote:
These vars could never have that type of situation due to how they get their data
But in cases where your development and coding is outsourced (and maybe even internal), this is a bad premise in itself, since they will cut and paste so MUCH of your existing code base, the error these two variables 'will never encounter' will show up everywhere else in your code.
-
Found this bit of VB/VBA code to be interesting! :D
If (Len(Replace(colourStyle, AP_colourStyle, "")) = 0) then
For some reason it took me a little while to realize that it simply meant:if (Trim$(colourStyle) = Trim$(AP_colourStyle)) then
:-O I could probably leave out the trim$() calls, but I like to make sure there are no pesky extra surronding spaces. -EMBoth code goes to the category of Hall of Shame? :wtf: