May 12, 2021 ASP.NET
Variables are named entities that are used to store data.
Variables are used to store data.
The name of a variable must begin with a letter character and cannot contain spaces or reserve characters.
A variable can be a specified type that represents the type of data it stores.
The string variable stores string values ("Welcome w3cschool.cn"), the integer variable stores the numeric value (103), the date variable stores the date value, and so on.
Variables are declared using the Dim keyword, or by using a type if you want to declare a type, but ASP.NET usually automatically determines the data type.
Common data types are listed below:
type | describe | Example |
---|---|---|
integer | Integer (full number) | 103, 12, 5168 |
double | 64-bit floating point number | 3.14, 3.4e38 |
decimal | Decimal number (high precision) | 1037.196543 |
boolean | Boolean value | true, false |
string | String | "Hello w3cschool.cn", "John" |
The operator tells the ASP.NET what kind of commands are executed in the expression.
The VB language supports a variety of operators. Common operators are listed below:
Operator | describe | Example |
---|---|---|
= | Assign a variable. | i=6 |
+
- * / |
Add a value or a variable.
Lower a value or a variable. Multiply one value or a variable. Remove with a value or a variable. |
i=5+5
i=5-5 i=5*5 i=5/5 |
+=
-= |
The variable is incremented.
Variables are decremented. |
i += 1
i -= 1 |
= | equal.Returns true if the value is equal. | if i=10 |
<> | Not equal.Returns true if the value is inequal. | if <>10 |
<
> <= >= |
Smaller than.
more than the. It is less than or equal. greater or equal to. |
if i<10
if i>10 if i<=10 if i>=10 |
& | Connect strings (a series of interrelated things). | "w3" & "schools" |
. | Dot number.Separate objects and methods. | DateTime.Hour |
() | Parentheses.Group values. | (i+5) |
() | Parentheses.Transfer parameters. | x=Add(i,5) |
() | Parentheses.Access the value of an array or a collection. | name(3) |
Not | No.Real / false. | if Not ready |
And
OR |
Logic and.
Logic or. |
if ready And clear
if ready Or clear |
AndAlso
orElse |
Extended logic and.
Extended logic or. |
if ready AndAlso clear
if ready OrElse clear |
It is sometimes useful to convert from one data type to another.
The most common example is converting string input to another type, such as an integer or date.
In general, user input is treated as string processing, even if the user enters a number. The numeric input must therefore be converted to a number before it can be used for calculations.
The common conversion methods are listed below:
method | describe | Example |
---|---|---|
AsInt()
IsInt() |
The conversion string is an integer. |
if myString.IsInt() then
myInt=myString.AsInt() end if |
AsFloat()
IsFloat() |
The conversion string is the floating point number. |
if myString.IsFloat() then
myFloat=myString.AsFloat() end if |
AsDecimal()
IsDecimal() |
The conversion string is a decimal number. |
if myString.IsDecimal() then
myDec=myString.AsDecimal() end if |
AsDateTime()
IsDateTime() |
The conversion string is the ASP.NET DATETIME type. |
myString="10/10/2012"
myDate=myString.AsDateTime() |
AsBool()
IsBool() |
The conversion string is the Boolean value. |
myString="True"
myBool=myString.AsBool() |
ToString() | Convert any data type as a string. |
myInt=1234
myString=myInt.ToString() |
These are the basics of variables, operators, data types, and transformations of data types related to VB variables in this section.