Initials of vb.net (Variables and Constants)
https://letsknowaboutcomputer.blogspot.com/2011/12/initials-of-vbnet.html
Types of Variables
You’ve learned how to declare variables and that all variables should have a type. But what
data types are available? Visual Basic recognizes the following five categories of variables:
◆ Numeric
◆ String
◆ Boolean
◆ Date
◆ Object
The two major variable categories are numeric and string. Numeric variables store numbers,
and string variables store text. Object variables can store any type of data.
Numeric Variables
You’d expect that programming languages would use the same data type for numbers. After
all, a number is a number. But this couldn’t be further from the truth. All programming languages
provide a variety of numeric data types, including the following:
◆ Integer (there are several Integer data types)
◆ Decimal
◆ Single (floating-point numbers with limited precision)
◆ Double (floating-point numbers with extreme precision)
Declearing variables
Byte Variables
Dim n As Byte
Dim A As Byte, B As Byte
A = 233
B = 50
Boolean Variables
The Boolean data type stores True/False values.
Dim running As Boolean
If running = True Then
running = False
Else
running = True
End If
String Variables
The String data type stores only text.
Dim aString As String
aString = “Now is the time for all good men to come ”
“to the aid of their country”
aString = “”
aString = “There are approximately 25,000 words in this chapter”
aString = “25,000”Dim aNumber As Integer = 25000
Dim aString As String = “25,000”
Character Variables
Character variables store a single Unicode character in two bytes. In effect, characters are
Unsigned Short integers (UInt16), but the Framework provides all the tools you need to work
with characters without having to resort to their numeric values (a very common practice for
the older among us)
Dim char1 As Char = “a”, char2 As Char = “ABC”
Debug.WriteLine(char1)
Debug.WriteLine(char2)
Date Variables
Date variables store date values that may include a time part (or not),
Dim expiration As Date
The following are all valid assignments:
expiration = #01/01/2010#
expiration = #8/27/1998 6:29:11 PM#
expiration = “July 2, 2011”
expiration = Today()
Today() function returns the current date and time, while the Now() function
returns the current date.Constants
Some variables don’t change value during the execution of a program. These variables are constants that appear many times in your code. For instance, if your program does math calculations, the value of pi (3.14159. . .) might appear many times. Instead of typing the value 3.14159 over and over again, you can define a constant, name it pi, and use the name of the constant in your code. The statement
circumference = 2 * pi * radius
is much easier to understand than the equivalent
circumference = 2 * 3.14159 * radius
Constants also have a scope and can be Public or Private. The constant pi, for instance, is usually declared in a module as Public so that every procedure can access it:
Public Const pi As Double = 3.14159265358979.