|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Which is the better construct?I am curious to know which IF statement below is better. strQCType
could be "LCS", "MS", "REG", "LD", or "LB". I want the code within the IF statements to execute only in the event of an "LCS" or "MS". If ((strQCType = "LCS") Or (strQCType = "MS")) Then End If -OR- If (strQCType = "LCS") Or (strQCType = "MS") Then End If Thanks, Vint v.ma***@comcast.net wrote:
Show quoteHide quote > I am curious to know which IF statement below is better. strQCType Personally, it makes no difference.> could be "LCS", "MS", "REG", "LD", or "LB". I want the code within the > IF statements to execute only in the event of an "LCS" or "MS". > > If ((strQCType = "LCS") Or (strQCType = "MS")) Then > > End If > > > -OR- > > > If (strQCType = "LCS") Or (strQCType = "MS") Then > > End If > > Thanks, > Vint -- Tom Shelton Tom,
:-) I am sure you missed that Or. CorShow quoteHide quote "Tom Shelton" <t**@mtogden.com> schreef in bericht news:1158866645.901276.17120@k70g2000cwa.googlegroups.com... > > v.ma***@comcast.net wrote: >> I am curious to know which IF statement below is better. strQCType >> could be "LCS", "MS", "REG", "LD", or "LB". I want the code within the >> IF statements to execute only in the event of an "LCS" or "MS". >> >> If ((strQCType = "LCS") Or (strQCType = "MS")) Then >> >> End If >> >> >> -OR- >> >> >> If (strQCType = "LCS") Or (strQCType = "MS") Then >> >> End If >> >> Thanks, >> Vint > > Personally, it makes no difference. > > -- > Tom Shelton > Cor Ligthert [MVP] wrote:
> Tom, Yes, I did. I only saw the parens. That's what comes of not doing VB> > :-) I am sure you missed that Or. > > Cor every day :) -- Tom Shelton > I am curious to know which IF statement below is better. strQCType If I am not missing something, they are the same. That brackets don't> could be "LCS", "MS", "REG", "LD", or "LB". I want the code within the > IF statements to execute only in the event of an "LCS" or "MS". make the difference. Quicker version would be: If (strQCType = "LCS") OrElse (strQCType = "MS") Then End If "Josip Medved" <jmed***@jmedved.com> schrieb: ACK, that's what I'd use too. Most developers coming from VB6 still use >> I am curious to know which IF statement below is better. strQCType >> could be "LCS", "MS", "REG", "LD", or "LB". I want the code within the >> IF statements to execute only in the event of an "LCS" or "MS". > > If I am not missing something, they are the same. That brackets don't > make the difference. Quicker version would be: > > If (strQCType = "LCS") OrElse (strQCType = "MS") Then > > End If 'Or' even if 'OrElse' makes more sense... -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/> Herfried,
Can you explain too me why you are using this and not simple. If strQCType = "LCS" OrElse strQCType = "MS" Then I am curious about you answer, I don't see any benefit from what (you tell) you are doing. Cor Show quoteHide quote "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> schreef in bericht news:usvyi4c3GHA.4164@TK2MSFTNGP05.phx.gbl... > "Josip Medved" <jmed***@jmedved.com> schrieb: >>> I am curious to know which IF statement below is better. strQCType >>> could be "LCS", "MS", "REG", "LD", or "LB". I want the code within the >>> IF statements to execute only in the event of an "LCS" or "MS". >> >> If I am not missing something, they are the same. That brackets don't >> make the difference. Quicker version would be: >> >> If (strQCType = "LCS") OrElse (strQCType = "MS") Then >> >> End If > > ACK, that's what I'd use too. Most developers coming from VB6 still use > 'Or' even if 'OrElse' makes more sense... > > -- > M S Herfried K. Wagner > M V P <URL:http://dotnet.mvps.org/> > V B <URL:http://dotnet.mvps.org/dotnet/faqs/> "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> schrieb: I would not write the '(...)' too, but writing the '(...)' may improve > Can you explain too me why you are using this and not simple. > > If strQCType = "LCS" OrElse strQCType = "MS" Then > > I am curious about you answer, I don't see any benefit from what (you > tell) you are doing. readability for those who do not have the exact rules for operator precedence in their mind. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Show quote
Hide quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message I tend to do that. The (..) are superfluous, but they do clarify what is news:uzqWl1k3GHA.1608@TK2MSFTNGP04.phx.gbl... : : "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> schrieb: : > : > Can you explain too me why you are using this and not simple. : > : > If strQCType = "LCS" OrElse strQCType = "MS" Then : > : > I am curious about you answer, I don't see any benefit from what (you : > tell) you are doing. : : I would not write the '(...)' too, but writing the '(...)' may improve : readability for those who do not have the exact rules for operator : precedence in their mind. happening. And I'm all for being clear about my intentions when coding. These two statement are equivalent: [1] If Not A AndAlso B Then [2] If (Not A) AndAlso (B) Then However, I find the second contruction to be clearer. It explicitly prevents the reader from interpreting this as [3] If Not (A AndAlso B) Then If I did in fact intend this third implementation, it is immediately obvious if that is what I achieved. I don't know how many times I've had to debug code where I've run into just this type of error. Adding the (...) would have prevented that right up front. I don't always bother for small, throw away code. But when I'm working in a team environment, I personally like using (...), superfluous or not, because it makes my intentions clear to the other coders. Ralf -- -- ---------------------------------------------------------- * ^~^ ^~^ * * _ {~ ~} {~ ~} _ * * /_``>*< >*<''_\ * * (\--_)++) (++(_--/) * ---------------------------------------------------------- There are no advanced students in Aikido - there are only competent beginners. There are no advanced techniques - only the correct application of basic principles. Herfried,
A good question for you , all that is inside a () should be processed first. Is this processed before the check on OrElse. In my opinion it should but than be not direct not wanted behaviour. Just my thought, and a nice question for you in my idea. Cor Show quoteHide quote "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> schreef in bericht news:uzqWl1k3GHA.1608@TK2MSFTNGP04.phx.gbl... > "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> schrieb: >> Can you explain too me why you are using this and not simple. >> >> If strQCType = "LCS" OrElse strQCType = "MS" Then >> >> I am curious about you answer, I don't see any benefit from what (you >> tell) you are doing. > > I would not write the '(...)' too, but writing the '(...)' may improve > readability for those who do not have the exact rules for operator > precedence in their mind. > > -- > M S Herfried K. Wagner > M V P <URL:http://dotnet.mvps.org/> > V B <URL:http://dotnet.mvps.org/dotnet/faqs/> > A good question for you , all that is inside a () should be processed Inside of all () is not processed before OrElse.> first. > Is this processed before the check on OrElse. > In my opinion it should but than be not direct not wanted behaviour. > Just my thought, and a nice question for you in my idea. If (something1) OrElse (something2) Then and If something1 OrElse something2 Then are completely the same. You can test it. :) Josip,
Thanks I would have done it, but yesterday I had no time for this, and if you say it, why would I not believe you? Cor Show quoteHide quote "Josip Medved" <jmed***@jmedved.com> schreef in bericht news:1158959176.916465.283940@i3g2000cwc.googlegroups.com... >> A good question for you , all that is inside a () should be processed >> first. >> Is this processed before the check on OrElse. >> In my opinion it should but than be not direct not wanted behaviour. >> Just my thought, and a nice question for you in my idea. > > Inside of all () is not processed before OrElse. > > If (something1) OrElse (something2) Then > > and > > If something1 OrElse something2 Then > > are completely the same. You can test it. :) > > -- > Greetings, > Josip Medved > http://www.jmedved.com > Hi,
Beside the OrElse and removing all parenthises you have to investigate what is used the most, that has be the first thing to investigate, that will at least save you 1 picosecond when 1000000000000 times used. However, all kind of investigating time used in this kind of question can in my idea never be gained by the time the program is going faster. Just my thought. Cor <v.ma***@comcast.net> schreef in bericht Show quoteHide quote news:1158865456.926903.110450@i3g2000cwc.googlegroups.com... >I am curious to know which IF statement below is better. strQCType > could be "LCS", "MS", "REG", "LD", or "LB". I want the code within the > IF statements to execute only in the event of an "LCS" or "MS". > > If ((strQCType = "LCS") Or (strQCType = "MS")) Then > > End If > > > -OR- > > > If (strQCType = "LCS") Or (strQCType = "MS") Then > > End If > > Thanks, > Vint > v.ma***@comcast.net wrote:
> I am curious to know which IF statement below is better. strQCType Personally, I wouldn't use an If for this at all!> could be "LCS", "MS", "REG", "LD", or "LB". I want the code within the > IF statements to execute only in the event of an "LCS" or "MS". Select Case strQCType Case "LCS", "MS" ' Do Useful stuff Case Else ' Do Something Else End Select IMHO it's more readible and, when you later decide that you need to do this processing for "REG" as well, it's far easier to change reliably. HTH, Phill W.
Problem calling a Sub in another form
WebBrowser - Excel processs till running Q: Copying part of a table Specifiy that i'm referring to a class, not a member StringReaders and DataWriters and FileStreams, oh, my! PrintDocument and HasMorePages issue Write commands to the COM port TextFieldParser - reading tab delimited file Refresh/Blinking Problems with VB.NET Application Calling Subprocedures |
|||||||||||||||||||||||