By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,061 Members | 1,563 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,061 IT Pros & Developers. It's quick & easy.

Using a colon ":" to Seperate Statements

P: n/a
Is it acceptable to use a colon ":" to seperate statements in VBA?

strVar1 = "A": lngVar2 = 0: blnVar3 = True
Msgbox strVar1: Msgbox lngVar2: Msgbox blnVar3

Thanks
Greg

Feb 16 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Ap******@gmail.com wrote:
>Is it acceptable to use a colon ":" to seperate statements in VBA?

strVar1 = "A": lngVar2 = 0: blnVar3 = True
Msgbox strVar1: Msgbox lngVar2: Msgbox blnVar3

It is legal syntax, but in many situations can make the code
difficult to read/debug. Use it sparingly or not at all.
--
Marsh
Feb 16 '07 #2

P: n/a
Ap******@gmail.com wrote:
Is it acceptable to use a colon ":" to seperate statements in VBA?

strVar1 = "A": lngVar2 = 0: blnVar3 = True
Msgbox strVar1: Msgbox lngVar2: Msgbox blnVar3
I was going to say don't be so silly, but before I did, I tried:

Function test()

MsgBox "hi": MsgBox "hello": MsgBox "What cha doin?"

End Function

And I'll be a monkey's uncle, it works!!!

So I guess it's acceptable. 8) I would find it hard to read and follow
if I were looking at code, though.
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Be Careful, Big Bird!" - Ditto "TIM-MAY!!" - Me
Feb 16 '07 #3

P: n/a
I was surprised to see this work also, since the colon seemed to be
reserved to the GoTo or Resume statements. That's why I was wondering
if there would be problems?

As far as readability goes, there are instances (like initializations)
that would make for cleaner reading, rather than introducing some many
lines:

VarA=0: VarB=0: VarC=0: VarD=0
VarE=1: VarF=3: VarG=5: VarH=7
VarK=2: VarL=4: VarM=6: VarN=8

VarA=0
VarB=0
VarC=0
VarD=0
VarE=1
VarF=3
VarG=5
VarH=7
VarK=2
VarL=4
VarM=6
VarN=8
Etc...............

Feb 16 '07 #4

P: n/a
Ap******@gmail.com wrote:
>I was surprised to see this work also, since the colon seemed to be
reserved to the GoTo or Resume statements. That's why I was wondering
if there would be problems?

As far as readability goes, there are instances (like initializations)
that would make for cleaner reading, rather than introducing some many
lines:

VarA=0: VarB=0: VarC=0: VarD=0
VarE=1: VarF=3: VarG=5: VarH=7
VarK=2: VarL=4: VarM=6: VarN=8

VarA=0
VarB=0
VarC=0
VarD=0
VarE=1
VarF=3
VarG=5
VarH=7
VarK=2
VarL=4
VarM=6
VarN=8
Etc...............

That's about the only time I use it. Another is the cleanup
code:
rs.Close : Set rs = Nothing

--
Marsh
Feb 16 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.