Using colons to put two statements on the same line in Visual Basic [closed] Using colons to put two statements on the same line in Visual Basic [closed] vba vba

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.


In general, I'd advise against it, as it makes for busier code.

However, for simple tasks, there is nothing wrong with it. For instance:

for i = 1 to 10: ProcessFoo(i): next

I think a line like this is short enough not to cause confusion.