459,576 Members | 1,360 Online
Need help? Post your question and get tips & solutions from a community of 459,576 IT Pros & Developers. It's quick & easy.

# One line IF statements

 100+ P: 365 Just a quick question.... Not really a fundamental one, just a general yes or no... ya know how ifs work... Expand|Select|Wrap|Line Numbers If Something = True Then       Do something End if Or Expand|Select|Wrap|Line Numbers If Something = True Then Do something is it possible to construct a "queue" of things to do in a single line? for example Expand|Select|Wrap|Line Numbers If Something = True Then Do something; Do something else Just curious, i often prefer the one line IF for short IF's (i think it looks tidier?) Dan Mar 8 '10 #1

Dan -

It's possible, by separating the statements to be executed with a ":" -

Expand|Select|Wrap|Line Numbers
1. If some condition true Then statement1 : statement2 : ... : statementN

But this is a good idea only for simple If constructs. For anything with more than one or two statements it is usually more readable to use the regular "block" form -

Expand|Select|Wrap|Line Numbers
1. If some condition true Then
2.      statement1
3.      statement2
4.      ...
5.      statementN
6. End If
7.

Pat

4 Replies

 Expert 100+ P: 931 Dan - It's possible, by separating the statements to be executed with a ":" - Expand|Select|Wrap|Line Numbers If some condition true Then statement1 : statement2 : ... : statementN But this is a good idea only for simple If constructs. For anything with more than one or two statements it is usually more readable to use the regular "block" form - Expand|Select|Wrap|Line Numbers If some condition true Then      statement1      statement2      ...      statementN End If   Pat Mar 8 '10 #2

 100+ P: 365 oh yeah i agree, complex things needthe full construct. i just found my self writing two almost identical lines which were very basic and thought.... hmmmmmmmmmmmm... i wonder IF Cheers Mar 8 '10 #3

 100+ P: 106 Hi, have you considered using SELECT CASE? Expand|Select|Wrap|Line Numbers SELECT CASE x  Case x=1st option  Do Something    Case x=2nd Option  Do Something   etc.   END SELECT   Mar 9 '10 #4

 100+ P: 365 I use select case statements regularly, my needs here are just to tidy up small simple statements, like procedure calls etc. Dan Mar 10 '10 #5