Using colons to put two statements on the same line in Visual Basic [closed]
There is nothing inherently wrong with using the colon to combine statements. It really depends on the context but as long as it doesn't reduce readability, there is nothing wrong with it.
As a general rule I avoid using the colon for this purpose. I find it's more readable to have one statement per line. However this is not a colon specific issue. I avoid doing the same with a semi-colon in C# or C++. It's just a personal preference.
It's a good practice in moderation, because sometimes readability is enhanced by concatenating two lines:
- when the lines are short and intimatelyrelated
when the lines are short and trivial
Option Compare Database: Option Explicit ''My favorite!rsDataSet.Close: Set rsDataSet= Nothing
Don't do it if:
- it hurts readability.
- it complicates debugging. Control structures such as
If...Then
need to stay clean. You'll be glad you kept it simple when it's time to set a break point. - it compromises future editing. Often you want to keep sections portable. Moving or re-structuring a block of code is easily hindered by attempts to minimize your code.