473,387 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Why not to recommend leaving off <>0 in conditionals

I was just working on fixing another programmer's code, and he has apparently
been told about the fact that you can omit comparisons with zero for If Then
statements because zero is false, and non-zero is True. The trouble is, he
generalized that statement to mean things it doesn't and has some very bad
logic as a result.

It was something like this...

If InStr(str1, "ABC") And Not InStr(str1, "DEF") Then

Of course, "And" is going to do a binary comparison here, so it will generally
fail to work properly when "DEF" is in the string. In most cases, the branch
-will- execute when "DEF" is in there.
Nov 12 '05 #1
2 1328


Well after the problem with equating 0 ==> False and Non-0 ==> True, it's
not so much the AND as the NOT that is the problem.

<g>

--
Terry Kreft
MVP Microsoft Access
"Steve Jorgensen" <no****@nospam.nospam> wrote in message
news:9a********************************@4ax.com...
I was just working on fixing another programmer's code, and he has apparently been told about the fact that you can omit comparisons with zero for If Then statements because zero is false, and non-zero is True. The trouble is, he generalized that statement to mean things it doesn't and has some very bad
logic as a result.

It was something like this...

If InStr(str1, "ABC") And Not InStr(str1, "DEF") Then

Of course, "And" is going to do a binary comparison here, so it will generally fail to work properly when "DEF" is in the string. In most cases, the branch -will- execute when "DEF" is in there.

Nov 12 '05 #2
Yes, but it's the "And" that makes it pass the initial tests, so the problem
likely won't be discovered until run-time.

On Fri, 23 Apr 2004 12:25:52 +0100, "Terry Kreft" <te*********@mps.co.uk>
wrote:


Well after the problem with equating 0 ==> False and Non-0 ==> True, it's
not so much the AND as the NOT that is the problem.

<g>


Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Eshrath | last post by:
Hi, What I am trying to do: ======================= I need to form a table in html using the xsl but the table that is formed is quite long and cannot be viewed in our application. So we are...
2
by: Donald Firesmith | last post by:
I am having trouble having Google Adsense code stored in XSL converted properly into HTML. The <> unfortunately become &lt; and &gt; and then no longer work. XSL code is: <script...
3
by: ajay2552 | last post by:
Hi, I have a query. All html tags start with < and end with >. Suppose i want to display either '<' or '>' or say some text like '<Company>' in html how do i do it? One method is to use &lt,...
14
by: Michael | last post by:
Since the include function is called from within a PHP script, why does the included file have to identify itself as a PHP again by enclosing its code in <?php... <?> One would assume that the...
13
by: baltasarq | last post by:
Hi, there ! When I use dynamic_cast for a single object, I do something like: void foo(Base *base) { if ( dynamic_cast<Derived *>( base ) != NULL ) { ((Derived *) base)->do_something() } }
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.