Download presentation
Presentation is loading. Please wait.
Published byRobyn Osborne Modified over 9 years ago
1
VB DATATYPES, VARIABLES, CONSTANTS & CALCULATIONS
2
Visual Basic Events When a Visual basic program runs, the form and its controls appear on the screen ‘action’. clicking a control pressing a key an event 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. three steps The three steps in creating a VB.NET program :
3
Visual Basic Events Create the interface Create the interface generate, position, and size the objects. Set properties Set propertiesconfigure the appearance of the objects. Write the code Write the code executes when events occur. Event-driven programming where the programs allow responding to many different input or events. This is called Event-driven programming where the programs allow responding to many different input or events.
4
VISUAL BASIC.NET DATA TYPES Data type Data type is a class that is primarily used just to hold type of data of variables…
5
.NET Data types Data TypeSize in BytesDescriptionType Byte18-bit unsigned integerSystem.Byte Char216-bit Unicode charactersSystem.Char Integer432-bit signed integerSystem.Int32 Double8 64-bit floating point variable System.Double Long864-bit signed integerSystem.Int64 Short216-bit signed integerSystem.Int16 Single4 32-bit floating point variable System.Single StringVariesNon-Numeric TypeSystem.String Date8System.Date Boolean2Non-Numeric TypeSystem.Boolean Object4Non-Numeric TypeSystem.Object Decimal16 128-bit floating point variable System.Decimal
6
Properties in 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: Property Data Type namestring Textstring visibleboolean multilineboolean
7
VARIABLES store Used to store data in memory., and later retrieve them. names, data types, and values 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.
8
The name, data type and an optional initial value of each variable is specified with a D DD Dim statement. Dim stands for Dimension. D 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: For example: consider the following Dim statements: Dim strName As String = "Bob" Dim intAge As Integer = 21 Dim sglPay As 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
11
WWe made up variable names that indicate the data type (str, int, sgl) and the meaning (name, age, pay rate). AA variable name can be anything you wish, but words that have specific meaning in Visual Basic, like "Dim" or "CInt," are r rr reserved words (or Keywords) and cannot be used as variable names. NNote: 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 ("").
12
Examples: Initialization !! Numeric variables are automatically initialized to 0: Dim varName As Double To specify a nonzero initial value Dim varName As Double = 50 Or Dim varName As Double VarName = 50
13
Cont.. Examples: Incrementing !! To add 1 to the numeric variable var var = var + 1 Or as a shortcut var +=1
14
copy Cont.. Examples: Integer Data Type !! An integer is a whole number.. Declaring an integer variable: Dim varName As 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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.