Setting the BackColor Property (Continue)
Way 2: Using the Colors Constants
First of all, what is Constant?
Constant is a variable that its value can not be changed.
Constant holds a common used value.
For example, the Constant vbRed holds the value
of the red color - &H000000FF&
Instead of writing in your code:
Command1.BackColor = &H000000FF&
You can write:
Command1.BackColor = vbRed
The 2 statements above are identical, because
vbRed = &H000000FF&
Where are these constants came from?
Visual Basic automatic declare them
when the program starts.
Imagine it like as the following code is
automatic being entered to your program:
Dim vbRed As Long
vbRed = &H000000FF&
Dim vbBlue As Long
vbBlue = &H00FF0000&
And so on...
But with one exception: You can't
change the constants value.
For example, the following code is NOT allowed:
vbBlue = 5
There are more Color constants, a partial list:
vbRed, vbBlue, vbBlack, vbGreen, vbWhite, vbYellow
You can declare your own constants.
The constant declaration syntax:
Const MyVariableName = MyVariableValue
For example, the following code will declare a const
variable with the name Piano and the (const) value "abcdef"
Const Piano = "abcdef"
After this declaration, the Print Piano
code line will print abcde on the form.
In addition, the following code line will not be allowed:
Piano = "gggg"
Because it's been declared as a Const,
and Const value can not be changed.
To learn more advanced programming techniques like
conditional statements, go to the Conditional Statements Tutorial.
Popular Posts
-
1.1 Code in a Highly Distributed World Software that addresses the Internet must be able to communicate. However, the Internet is n...
-
SQL is short for Structured Query Language and is a widely used database language, providing means of data manipulation (store, retrieve, up...
-
As you learned in one of the previous chapters, SQL Management Studio can be used to manage multiple instances of SQL Server . However, when...
-
As mentioned on the .NET Framework page, .NET Framework is designed for cross-language compatibility. Cross-language compatibility means .NE...
-
The SQL AND clause is used when you want to specify more than one condition in your SQL WHERE clause, and at the same time you want all con...
-
5.3 Draw.aspx Web Applications I am just about to finish this tutorial. I have given you a couple of code samples to chew on, but t...
-
STRINGS: The way a group of integers can be stored in an integer array, similarly a group of characters can be stored in a character array. ...
-
5.1 The .NET Framework: Big Picture Figure 5‑1 The .NET Framework in Context Looking at Figure 5‑1 we see the lifespan of managed c...
-
4.3 Using the FCL “Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime.” The IO strea...
-
Simple Binding Data Binding Data Binding is binding controls to data from the database. With data binding we can bind a control to a partic...
No comments:
Post a Comment