Use constants, not variables
If you want to emulate the vb color "variables", you simply use named constants. That's what vbRed is. When using vbRed in your program, you can use the named constant (vbRed) or the actual long value (255) or the actual hexadecimal value (&HFF)...all will give you the same results.
To create a constant, create it in the General Declarations as Private (or in a Module as Public ) like so:
Code:
'Syntax:
<Scope> Const <Name> As <Type> = <Value>
'Example:
Private Const MyName As String = "seaweed"
Here's an example using constants in a program. I basically made my own constants for colors and used them instead of VB's intrinsic color constants.
Start a new project and drop a command button on a form (keep the default name). Paste the following code into the form's code window, run the project, and click the command button.
Code:
Option Explicit
'My own color constants
Private Const MyRed As Long = 255
Private Const MyGreen As Long = 65280
Private Const MyBlue As Long = 16711680
Private Const MyYellow As Long = 65535
Private Const MyBlack As Long = 0
Private Const MyWhite As Long = 16777215
Private Const MyMagenta As Long = 16711935
Private Const MyCyan As Long = 16776960
Private Sub Command1_Click()
Static ClickNumber As Integer
'Keep ClickNumber in the range 0 to 7
If ClickNumber = 8 Then ClickNumber = 0
Select Case ClickNumber
Case 0
Form1.BackColor = MyRed
Case 1
Form1.BackColor = MyGreen
Case 2
Form1.BackColor = MyBlue
Case 3
Form1.BackColor = MyYellow
Case 4
Form1.BackColor = MyBlack
Case 5
Form1.BackColor = MyWhite
Case 6
Form1.BackColor = MyMagenta
Case 7
Form1.BackColor = MyCyan
End Select
'Increment ClickNumber
ClickNumber = ClickNumber + 1
End Sub