1 / 14

VB DATATYPES, VARIABLES, CONSTANTS & CALCULATIONS

VB DATATYPES, VARIABLES, CONSTANTS & CALCULATIONS. When a Visual basic program runs, the form and its controls appear on the screen ‘action’.

Download Presentation

VB DATATYPES, VARIABLES, CONSTANTS & CALCULATIONS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. VB DATATYPES, VARIABLES, CONSTANTS & CALCULATIONS

  2. When a Visual basic program runs, the form and its controls appear on the screen ‘action’. such as clicking a control or pressing a key. We call such an action an event. The programmer writes code that reacts to an event by performing some functionality. The three steps in creating a VB.NET program : Visual Basic Events

  3. Create the interface generate, position, and size the objects. • Set propertiesconfigure the appearance of the objects. • Write the code executes when events occur. This is called Event-driven programming where the programs allow responding to many different input or events. Visual Basic Events

  4. Data type is a class that is primarily used just to hold type of data of variables… VISUAL BASIC.NET DATA TYPES

  5. .NET Data types

  6. Propertiesin VB controls also have data types, and when we assign values to the properties, those values must be of proper data type. • Think back to some of the properties we have been using -- each has its own data type:

  7. Used to store data in memory., and later retrieve them. • Like the properties of objects, variables have names, data types, and values. As the name implies, the values of variables can change (vary) during the execution of the program. VARIABLES

  8. The name, data type and an optional initial value of each variable is specified with a Dim statement. Dim stands for Dimension. • Dim <variable name> as <data type> [=expiration] • when the Dim statement is executed the compiler sets aside space in memory to hold it's value. (The amount of memory it needs to set aside depends upon the data type).

  9. For example: consider the following Dim statements: DimstrNameAs String = "Bob" DimintAgeAs Integer = 21 DimsglPayAs Single = 7.50 When the computer executes these instructions, it would construct three variables, setting aside space in memory for each and assigning it the appropriate initial values

  10. We made up variable names that indicate the data type (str, int, sgl) and the meaning (name, age, pay rate). • A variable name can be anything you wish, but words that have specific meaning in Visual Basic, like "Dim" or "CInt," are reserved words (or Keywords) and cannot be used as variable names. • Note: The syntax of the Dim statement indicates that expression giving the initial value is optional. If it is not specified, numeric variables are assigned an initial value of zero (0) and string variables are assigned an initial value of Null ("").

  11. Examples: Initialization !! Numeric variables are automatically initialized to 0: DimvarNameAs Double To specify a nonzero initial value DimvarNameAs Double = 50  Or DimvarNameAs Double VarName = 50

  12. Cont .. Examples: Incrementing !! To add 1 to the numeric variable var var = var + 1 Or as a shortcut var +=1

  13. Cont .. Examples: Integer Data Type !! An integer is a whole number .. Declaring an integer variable: DimvarNameAs Integer Multiple Declarations Dim a, b As Double Two other types of multiple-declaration statements are Dim a As Double, b As Integer Dim c As Double = 2, b As Integer = 5 copy

More Related