0% found this document useful (0 votes)
2 views1 page

Visual Basic Variables and Formulas

The document explains the use of variables in Visual Basic, highlighting their role as temporary storage for data. It details how to declare a variable using the Dim statement and the importance of specifying the variable type for memory allocation. Additionally, it demonstrates how to assign values to variables and use them in code, such as displaying a name in a label.

Uploaded by

Miriam Pidul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Visual Basic Variables and Formulas

The document explains the use of variables in Visual Basic, highlighting their role as temporary storage for data. It details how to declare a variable using the Dim statement and the importance of specifying the variable type for memory allocation. Additionally, it demonstrates how to assign values to variables and use them in code, such as displaying a name in a label.

Uploaded by

Miriam Pidul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

VISUAL BASIC VARIABLES AND FORMULAS, AND THE .

NET FRAMEWORK

Using Variables to Store Information

A variable is a temporary storage location for data in your program. You can use one or many
variables in your code, and they can contain words, numbers, dates, properties, or other values.

Setting Aside Space for Variables: The Dim Statement

To declare a variable in Visual Basic 2010, type the variable name after the Dim statement. (Dim
stands for dimension.) This declaration reserves room in memory for the variable when the program
runs and lets Visual Basic know what type of data it should expect to see later.

For example, the following statement creates space for a variable named LastName that will hold a
textual, or string, value:

Dim LastName As String

Note that in addition to identifying the variable by name, we used the As keyword to give the variable
a particular type, and I’ve identified the type by using the keyword String.

A string variable contains textual information: words, letters, symbols—even numbers. They hold
names, places, lines from a poem, the contents of a file, and many other “wordy” data.

Why do you need to declare variables? Visual Basic wants you to identify the name and the type of
your variables in advance so that the compiler can set aside the memory the program will need to
store and process the information held in the variables.

After you declare a variable, you’re free to assign information to it in your code by using the
assignment operator (=). For example, the following program statement assigns the last name
“Jefferson” to the LastName variable:

LastName = "Jefferson"

Be careful to assign a textual value to the LastName variable because its data type is String. I can also
assign values with spaces, symbols, or numbers to the variable, such as

LastName = "1313 Mockingbird Lane"

After the LastName variable is assigned a value, it can be used in place of the name “Jefferson” in
your code. For example, the assignment statement

Label1.Text = LastName

displays

“Jefferson” in the label named Label1 on a form

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy