472,780 Members | 1,770 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,780 software developers and data experts.

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 9782
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.