In this chapter Declaring and Naming Variables Understanding Data Types Working with Numeric Data Types Using Math Operations Using Date and Time Values Working with Strings Using Arrays Understanding Regional Settings Exercise: Parsing Strings In this chapter we will discuss variables. Variables are used to store information in the computer's memory while your programs are running. Three components define a variable: The variable's name (which correlates to its location in memory) The type of information being stored The actual information itself Suppose you are given this assignment: "Go count all the cars in the parking lot." As you count each car, you are storing information in a variable. Your location in memory is either a notepad or your brain. The type of information being stored is a number. And the actual information you are storing is the current number of cars. As the name variable suggests, the information stored in a variable can change (vary) over time. In the example of counting cars, the count will be increased periodically. With any variable, there are two basic functions you can perform: storing information (writing on the notepad) and retrieving information (reading what is written on the notepad). An assignment statement is used to store information in a variable, as in the following example: Dim LoneliestNumber As Integer LoneliestNumber = 1 In the example, the variable name is LoneliestNumber, the type of the variable is Integer, and the value being stored is the number 1. Note Many of the code samples in this chapter will be simple one- or two-line examples. To try any of these code samples, perform the following steps: -
Create a new Windows Application Project. -
Place a button on the form. -
Put the sample lines of code in the button's Click event. -
Use either the Debug.WriteLine function or the MessageBox.Show function to display the result. You can use the same sample application for all the code samples in this chapter. The code for the major examples can be downloaded from the Web. |