What is faster? "Not =" or <> ? (Super Easy ?)

which would execute faster, and what is better codeing convention?

if A <> 1 then mysub

or

if Not A = 1 then mysub

thanks
JaysorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mark2150Commented:
Depends on the nature of A. I'd generally prefer the first form if A is an integer. The second form you're showing should be:

IF NOT (A = 1) THEN CALL MySub

The paren's help the compiler know you're after a logical result.

Overall I think the first form would be faster.

However, there are some cases when you can get around having an IF altogether. Suppose you're showing/hiding a control on the basis of a control value. Lets say we only want to enable a button if some value is non-zero. You might code:

IF SomeValue = 0 THEN
  MyButton.Enabled = True
ELSE
  MyButton.Enabled = False
END IF

However you can simplify this to:

MyButton.Enabled = (SomeValue = 0)

The compiler will evaluate the (SomeValue = 0) clause as either TRUE or FALSE and will therefore be able to use that to change the boolean state of the control's .Enabled property. This is four less lines of code and assures that you can't accidentially forget to code the "bottom half" of the conditional.

M
0
JaysorAuthor Commented:
Adjusted points to 15
0
JaysorAuthor Commented:
thanks for the () tip. also what do you think about boolean valuse? ie:

If Not myBoolean Then MySub or

If myBoolean = False then MySub

0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

amebaCommented:
The fastest is:
   If Not A - 1 Then mysub
0
mark2150Commented:
Jaysor,

I prefer the first form as long as myBoolean is a "real" boolean. I've got some legacy code where the original programmer used integers with 0 for false and 1 for true.

I do also prefer the CALL MySub rather than the straight MySub. This also helps make it clear that it's a sub an not a function, but that is more a matter of taste than anything else.

Ameba, didn't you mean:

If not A = 1 ...

instead of

if not A - 1 ...

?

M
0
amebaCommented:
>Ameba, didn't you mean:
>If not A = 1 ...
No. Comparison is slower then mathematical operation.

Also,  
   If not X
is faster then
   If X = 0
and "Not" statement works on all numeric types.
0
amebaCommented:
Also, for strings:
' veeery slow:
  If X = "" Then

' fast
  If len(X) = 0 Then

' faster
  If len(X) Then
0
amebaCommented:
>Also,  
>   If not X
>is faster then
>   If X = 0
>and "Not" statement works on all numeric types.

Sorry, that is not correct. This is correct:
   If not CBool(X)
is faster then
   If X = 0

See also:
http://www.vb2themax.com/Item.asp?PageID=TipBank&ID=129
http://www.vb2themax.com/Item.asp?PageID=TipBank&ID=119 (mark mentioned this)
You can find many tips in TipBank section.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
paul_tsekovCommented:
Hi VBfan,
1.
When using Boolean values,
use Not()
2.
When using integer and numberic values
use <>
  The <> works better and looks better if you have some numberic value.
  The Not looks better but doesn't work better if you have a boolean value.

When using boolean values:
dim b as boolean
    if Not b then
        ...
    end if
    if b then
        ...
    end if

if preffered than :

It look better than
  if (b<>True) then
        ...
  end if
  if  (b<>False) then
       ...
  end if






if you have the numberic value:
     if a<>10 then
         ...
     end if
Is preffered than:
     if Not(a=10) then
         ...
     end if
and works faster.

         
   
              Pavel Tsekov
       email : paul_tsekov@yahoo.com
0
JaysorAuthor Commented:
Im rejecting it because "ameba's" answered first and was more consise with links! How could i ask for more!

0
JaysorAuthor Commented:
thanks for the links too!
0
amebaCommented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.