Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel VBA Colon [duplicate]

Tags:

excel

vba

Possible Duplicate:
VB Using colons to put two statements on same line

I have the following declaration in Excel VBA

Public Const cdbArea = 1: Public Const cdbDist = 2: Public Const cdbChange1 = 4: Public Const cdbChange2 = 5: Public Const cdbTR = 5:
Public Const crbArea = 1: Public Const crbDist = 2: Public Const crbTerr = 3: Public Const crbChange1 = 4: Public Const crbTR = 5:
Public Const cdbWeek1 = 4

On first glance, the Colons look like separators, but I have never used this syntax before.

What are the Colons for?

like image 897
Raj More Avatar asked Nov 12 '09 20:11

Raj More


2 Answers

You can put the statements on separate lines, if you like:

Public Const cdbArea = 1
Public Const cdbDist = 2
Public Const cdbChange1 = 4

Or, you can separate them with colons as in your example above.

like image 103
BoltBait Avatar answered Sep 18 '22 10:09

BoltBait


Another use of the colon is to set specific variables to a calling statement:

Option Explicit

Sub test()
    testWithOptions thirdParameter:="SecondParameterSkipped", firstParameter:="firstParam"
End Sub

Sub testWithOptions(firstParameter As String, Optional secondParameter As String, Optional thirdParameter As String)
    MsgBox "FirstParamter:  " & firstParameter & vbCrLf & _
                "ThirdParamter:  " & thirdParameter
End Sub

Notice the third parameter is set before the first and secondParameter (which is optional) is skipped all together.

I've only seen this used once in my career.

like image 36
ray Avatar answered Sep 21 '22 10:09

ray