473,471 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Using a colon ":" to Seperate Statements

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
4 9814
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: adrien | last post by:
Hi, i start with javascript and i saw a lot of examples, but sometimes there is ";" on each end of line, sometimes only certain lines, sometimes nowhere. So my question is: where must i put ";"...
21
by: Evan Sussman | last post by:
Could any one give me an explenation of this error? I get it every once in a while, and it really is a pain. currently the code that I'm working with goes like this <script> <!-- var...
9
by: Jukka K. Korpela | last post by:
I noticed that Internet Explorer (6.0, on Win XP SP 2, all fixes installed) incorrectly renders e.g. &harr &euro &Omega literally and not as characters denoted by the entities, but if a semicolon...
8
by: Just Me | last post by:
1)How can I find the folders like "My Recent Document", "Desktop", "My Pictures",... if I want to store a file there? 2) How can I find the icon for those files if I want to display it? ...
43
by: markryde | last post by:
Hello, I saw in some open source projects a use of "!!" in "C" code; for example: in some header file #define event_pending(v) \ (!!(v)->vcpu_info->evtchn_upcall_pending & \...
3
by: MLH | last post by:
If I run ?", ","" in the immediate window, I get a comma followed by 13 spaces. It is difficult for me to understand this.
1
by: manchin2 | last post by:
Hi, Can anybody please provide the information about "&quot" and its use, if possible please provide an example. ...
2
by: Clint Stowers | last post by:
I have a query with a field name of "Street", however, I would like it to read "CAT:STREET". This query is exported to a csv file that requires the format of the later. Currently the csv file...
4
by: fran7 | last post by:
Hi, from help in the javascript forum I found the error in some code but need help. This bit of code works perfectly, trouble is I am writing it to a javascript function so the height needs to be in...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.