Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 623
Default Where do you put the 'Else'?

After an If statement, I indent all subsequent statements one tab until the
End If. However, I'm struggling with where to put the Else statement. I'd
like to know what convention other programmers follow. Do you:

1. Indent it with the other statements, even though it might be difficult to
find?
2. Keep it in line with the IF statement?
3. Split the difference, and indent it two spaces rather than four?

Thanks for your feedback,
Fred


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 575
Default Where do you put the 'Else'?

Fred,

Most of us would have

If condition Then
'do something
ElseIF condition
'do something
Else
'do something
End If

Robin Hammond
www.enhanceddatasystems.com

"Fred Smith" wrote in message
...
After an If statement, I indent all subsequent statements one tab until
the End If. However, I'm struggling with where to put the Else statement.
I'd like to know what convention other programmers follow. Do you:

1. Indent it with the other statements, even though it might be difficult
to find?
2. Keep it in line with the IF statement?
3. Split the difference, and indent it two spaces rather than four?

Thanks for your feedback,
Fred



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Where do you put the 'Else'?

Fred,

IDEs typically have the ability to understand code syntax. For instance,
functions would be highlighted with one color and parameters another. Same
goes for indenting. They automatically indent the code between the beginning
and end of any conditional statement or loop. If there's an ELSE in the
condition, the IDE will keep it inline with the IF. Obviously, all of the
syntax highlighting and indenting is only for the benefit of the programmer.
It has no affect on the way the code executes.

For VBA, some syntax highlighting is done, and there's an AutoIndent
CheckBox in the VBA Editor Options (but I've never actually seen any
difference with it Checked or unChecked!).

Cheers,
Lee

"Fred Smith" wrote in message
...
After an If statement, I indent all subsequent statements one tab until
the End If. However, I'm struggling with where to put the Else statement.
I'd like to know what convention other programmers follow. Do you:

1. Indent it with the other statements, even though it might be difficult
to find?
2. Keep it in line with the IF statement?
3. Split the difference, and indent it two spaces rather than four?

Thanks for your feedback,
Fred



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Where do you put the 'Else'?


"lgbjr" wrote in message
...
Fred,

IDEs typically have the ability to understand code syntax. For instance,
functions would be highlighted with one color and parameters another. Same
goes for indenting. They automatically indent the code between the

beginning
and end of any conditional statement or loop. If there's an ELSE in the
condition, the IDE will keep it inline with the IF. Obviously, all of the
syntax highlighting and indenting is only for the benefit of the

programmer.
It has no affect on the way the code executes.


VBA doesn't align the Else with the IF automatically it aligns to the
previous line. That would be useful.

For VBA, some syntax highlighting is done, and there's an AutoIndent
CheckBox in the VBA Editor Options (but I've never actually seen any
difference with it Checked or unChecked!).


Have you tried it? Unchecking it for me ignores any indenting and starts in
column 1.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Where do you put the 'Else'?

Fred,

Like Robin I align the IF ... Else, like so

If Condition Then
'do your stuff
ElseIf Condition2 Then
'do something else
Else
If Suib - Condition Then
'do yet more
Else
'but only if condition2 is met
End If
End If

Personally, I never use code like so

If a = b Then c = d

I always use

If a = b Then
c = d
End If

as I feel that the former can confuse in a lot of code, you go looking for
an EndIf that isn't there.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Fred Smith" wrote in message
...
After an If statement, I indent all subsequent statements one tab until

the
End If. However, I'm struggling with where to put the Else statement. I'd
like to know what convention other programmers follow. Do you:

1. Indent it with the other statements, even though it might be difficult

to
find?
2. Keep it in line with the IF statement?
3. Split the difference, and indent it two spaces rather than four?

Thanks for your feedback,
Fred




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 04:11 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"