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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With