ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Colon in code? (https://www.excelbanter.com/excel-programming/350294-colon-code.html)

davegb

Colon in code?
 
What does a colon in VBA code do? I.e.,

Hide:

I tried to figure out how to look this up both online and in
Walkenbach, but couldn't find anything on it.
Thanks.


Chip Pearson

Colon in code?
 
It separates two logical lines of code into a single line of
text. E.g., the following code snippets are functionally
equivalent:



Dim X As Long: X = 123

Dim X As Long
X = 123


"davegb" wrote in message
oups.com...
What does a colon in VBA code do? I.e.,

Hide:

I tried to figure out how to look this up both online and in
Walkenbach, but couldn't find anything on it.
Thanks.




Chip Pearson

Colon in code?
 
I should have added that the colon is also used to label a
location in code, typically used for On Error Goto Label
statements.

On Error GoTo ErrH:
' some code
ErrH:
' error code here


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"davegb" wrote in message
oups.com...
What does a colon in VBA code do? I.e.,

Hide:

I tried to figure out how to look this up both online and in
Walkenbach, but couldn't find anything on it.
Thanks.




George Nicholson[_2_]

Colon in code?
 
In this case, I suspect "Hide:" is a line label (Colons can also be used to
separate multi commands on a single line, but that doesn't seem to be the
case here). There is probably a "GoTo Hide" instruction somewhere in the
same function/procedure where you found it (if there isn't, there probably
was one at some point in time and someone simply forgot to take the
corresponding label out.)

Use of line labels and goto's is (generally) frowned upon (outside of Error
trapping where they are a necessity). This has become one of those "rules to
be broken" because improper/overuse of them is an very easy trap for newbie
coders to fall into since there is (almost) always a better way to achieve
the same results. Extreme caution is advised or you could quickly end up
with "spaghetti code" that jumps all over the place: something totally
unreadable & unmanageable, even if you wrote it yourself yesterday.

"Line labels" doesn't warrant an entry in Help, but you can get to a
hyperlink definition of them via the entry for the "GoTo" statement.

Let's be careful out there...

HTH,
--
George Nicholson

Remove 'Junk' from return address.


"davegb" wrote in message
oups.com...
What does a colon in VBA code do? I.e.,

Hide:

I tried to figure out how to look this up both online and in
Walkenbach, but couldn't find anything on it.
Thanks.




davegb

Colon in code?
 

George Nicholson wrote:
In this case, I suspect "Hide:" is a line label (Colons can also be used to
separate multi commands on a single line, but that doesn't seem to be the
case here). There is probably a "GoTo Hide" instruction somewhere in the
same function/procedure where you found it (if there isn't, there probably
was one at some point in time and someone simply forgot to take the
corresponding label out.)

Use of line labels and goto's is (generally) frowned upon (outside of Error
trapping where they are a necessity). This has become one of those "rules to
be broken" because improper/overuse of them is an very easy trap for newbie
coders to fall into since there is (almost) always a better way to achieve
the same results. Extreme caution is advised or you could quickly end up
with "spaghetti code" that jumps all over the place: something totally
unreadable & unmanageable, even if you wrote it yourself yesterday.

"Line labels" doesn't warrant an entry in Help, but you can get to a
hyperlink definition of them via the entry for the "GoTo" statement.

Let's be careful out there...

HTH,
--
George Nicholson

Remove 'Junk' from return address.


"davegb" wrote in message
oups.com...
What does a colon in VBA code do? I.e.,

Hide:

I tried to figure out how to look this up both online and in
Walkenbach, but couldn't find anything on it.
Thanks.

Thanks for all your replys!



All times are GMT +1. The time now is 12:13 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com