View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Nedan Nedzatra Nedan Nedzatra is offline
external usenet poster
 
Posts: 10
Default If Statement Variations

Hia!

Chip!

Thank You.

I am Ok with the first 2 now. Could you please extend the 3rd as you
explained the second? I do not think I could get assistance on this from VBA
help; I am trying

"Chip Pearson" wrote:


What is if (something) ---- why do you need bracket?


You don't need the outer enclosing parentheses, but they are harmless
if included. Some programmers use them as a matter of personal coding
style, but they are not required to do so.

What is if xxxxx = 0& ----- why do you need €œ&€


In this context, the & character forces the compiler to use a Long
integer data type (32-bit signed) rather than a short Integer (16-bit
signed). It is required for some calculations whose inputs and result
may fit in a short integer but whose intermediate calculations
overflow a short Integer. For example, consider the following code:

Dim X As Integer
Dim Y As Integer
X = 30000
Y = (X * 2) / 2
Debug.Print Y

Here, the inputs and output of the calculation are within the bounds
of a short Integer (+/- 32K), but the intermediate calculation (X*2)
overflows a short integer and the code will blow up with an overflow
error. If you change the line of code to

Y = (X * 2&) / 2

the & character forces the compiler to use a Long integer when
calculating X*2, so there is no overflow error.


What is #if ----- why that €œ#€


The # character is for "conditional compilation". This allows you to
exclude blocks of the code from being compiled. In the end, it isn't
really any different than commenting out the same block of code, but
is simpler. For example, when you are developing and debugging a
program, you can set a DEBUG flag with the #CONST statement and then
test that flag to compile or not compile the block of code. This makes
it simpler to switch to and from debug and testing and production
code. E.g,

#CONST DEBUG = True
' lots of code
#If DEBUG = True Then
' diagnostic and trace code
#End If

Simply changing the single #CONST line can cause many debug and trace
blocks of code to be excluded in the production version. Much simpler
than try to remember which lines of code should be commented at
release.


Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]




On Tue, 12 Jan 2010 14:20:01 -0800, Nedan Nedzatra
wrote:

Hia!

How is the day going friends!

I am stuck into another crazy programming thing!!!

3 questions;

I know normal VBA if statements and Excel or SQL ifs. However;

What is if (something) ---- why do you need bracket?
What is if xxxxx = 0& ----- why do you need €œ&€
What is #if ----- why that €œ#€

Could someone explain?

.