# ASP.NET Razor - VB Variables

« Previous
Next Chapter »

Variables are named entities used to store data.

## Variables

Variables are used to store data.

The name of a variable must begin with an alphabetic character and cannot contain whitespace or reserved characters.
A variable can be of a specific type, indicating the kind of data it stores. String variables store string values ("Welcome to W3Schools"), integer variables store number values (103), date variables store date values, etc.
Variables are declared using the Dim keyword, or by using the type (if you want to declare the type), but ASP.NET can usually determine data types automatically.

## Examples

// Using the Dim keyword:
Dim greeting = "Welcome to W3Schools"
Dim counter = 103
Dim today = DateTime.Today
// Using data types:
Dim greeting As String = "Welcome to W3Schools"
Dim counter As Integer = 103
Dim today As DateTime = DateTime.Today

## Data Types

Below is a list of common data types:

Type | Description | Examples
--- | --- | ---
integer | Integer (whole numbers) | 103, 12, 5168
double | 64 bit floating-point number | 3.14, 3.4e38
decimal | Decimal number (higher precision) | 1037.196543
boolean | Boolean | true, false
string | String | "Hello W3Schools", "John"

## Operators

An operator tells ASP.NET what kind of command to perform in an expression.

The VB language supports many operators. Below is a list of common operators:

Operator | Description | Example
--- | --- | ---
= | Assigns a value to a variable. | i=6
+ - * / | Adds a value or variable. Subtracts a value or variable. Multiplies a value or variable. Divides a value or variable. | i=5+5 i=5-5 i=5*5 i=5/5
+= -= | Increments a variable. Decrements a variable. | i += 1 i -= 1
= | Equality. Returns true if values are equal. | if i=10
<> | Inequality. Returns true if values are not equal. | if <>10
< > <= >= | Less than. Greater than. Less than or equal. Greater than or equal. | if i<10 if i>10 if i<=10 if i>=10
& | Adding strings (concatenation). | "w3" & "schools"
. | Dot. Separate objects and methods. | DateTime.Hour
() | Parenthesis. Groups values. | (i+5)
() | Parenthesis. Passes parameters. | x=Add(i,5)
() | Parenthesis. Accesses values in arrays or collections. | name(3)
Not | Not. Reverses true or false. | if Not ready
And OR | Logical AND. Logical OR. | if ready And clear if ready Or clear
AndAlso orElse | Extended Logical AND. Extended Logical OR. | if ready AndAlso clear if ready OrElse clear

## Converting Data Types

Converting from one data type to another is sometimes useful.
The most common example is to convert string input to another type, such as an integer or a date.

As a rule, user input comes as strings, even if the user entered a number. Therefore, numeric input values must be converted to numbers before they can be used in calculations.

Below is a list of common conversion methods:

Method | Decryptions | Example
--- | --- | ---
AsInt() IsInt() | Converts a string to an integer. | if myString.IsInt() then myInt=myString.AsInt() end if
AsFloat() IsFloat() | Converts a string to a floating-point number. | if myString.IsFloat() then myFloat=myString.AsFloat() end if
AsDecimal() IsDecimal() | Converts a string to a decimal number. | if myString.IsDecimal() then myDec=myString.AsDecimal() end if
AsDateTime() IsDateTime() | Converts a string to an ASP.NET DateTime type. | myString="10/10/2012" myDate=myString.AsDateTime()
AsBool() IsBool() | Converts a string to a Boolean. | myString="True" myBool=myString.AsBool()
ToString() | Converts any data type to a string. | myInt=1234 myString=myInt.ToString()

« Previous
Next Chapter »

### WEB HOSTING

UK Reseller Hosting

### WEB BUILDING

FREE Website BUILDER Free HTML5 Templates

### W3SCHOOLS EXAMS

HTML, CSS, JavaScript, PHP, jQuery, XML, and ASP Certifications

### SHARE THIS PAGE

### Color Picker

### HTML/CSS

HTML Tutorial HTML5 Tutorial CSS Tutorial CSS3 Tutorial Bootstrap Tutorial

### JavaScript

JavaScript Tutorial jQuery Tutorial jQuery Mobile Tutorial AngularJS Tutorial AJAX Tutorial JSON Tutorial

### Graphics

Canvas Tutorial SVG Tutorial Google Maps Tutorial

### Server Side

SQL Tutorial PHP Tutorial ASP Tutorial ASP.NET Tutorial VBScript Tutorial AppML Tutorial

### Web

Web Building Web Statistics Web Certification

### XML

XML Tutorial DTD Tutorial Schema Tutorial XML DOM Tutorial XPath Tutorial XSLT Tutorial XQuery Tutorial XSL-FO Tutorial RSS Tutorial WSDL Tutorial

### HTML/CSS

HTML Tag Reference HTML Event Reference HTML Color Reference CSS 1,2,3 Reference Bootstrap Reference

### JavaScript

JavaScript Reference HTML DOM Reference jQuery Reference jQuery Mobile Reference Google Maps Reference

### Server Side

PHP Reference SQL Reference ASP Reference VBScript Reference Razor Reference ASP.NET Reference

### XML

XML DOM Reference XSLT Reference XSL-FO Reference XPath Reference XQuery Reference Schema Reference RSS Reference SVG Reference

### HTML Charsets

HTML Character Sets HTML ASCII HTML ANSI HTML Windows-1252 HTML ISO-8859-1 HTML Symbols HTML UTF-8

### HTML/CSS

HTML Examples CSS Examples

### Browser Scripting

JavaScript Examples HTML DOM Examples jQuery Examples jQuery Mobile Examples AngularJS Examples AJAX Examples

### Server Scripting

PHP Examples ASP Examples VBScript Examples Razor Examples .NET Examples

### XML Languages

XML Examples DTD Examples XML DOM Examples XSL Examples XSLT Examples XPath Examples XQuery Examples Schema Examples RSS Examples SVG Examples