Presentation is loading. Please wait.

Presentation is loading. Please wait.

Creation of Variables with Numeric, alphanumeric, date, picture, memo data types Constant - A quantity that does not change during the execution of a program.

Similar presentations


Presentation on theme: "Creation of Variables with Numeric, alphanumeric, date, picture, memo data types Constant - A quantity that does not change during the execution of a program."— Presentation transcript:

1 Creation of Variables with Numeric, alphanumeric, date, picture, memo data types Constant - A quantity that does not change during the execution of a program is called constant. Constant types are 1) Numeric constant 2) String constant 1)Numeric constant : It is nothing but number. Number can be expressed as integer quantities (whole number) or as decimal quantities (number with decimal point) example : 124 23.55 1299 -345 -45.78 2)String constant: A string is a sequence of characters (ie letters, numbers and special symbols such as +, -,@, $ etc) example: “RAJA” “JAMES BOND 007” “1234$”

2 Variable - A quantity that does change during the execution of a program is called variable. A variable is a data name that may be used to store a data value. - The address of the memory location is called variable. Rules :- - First character must be a letter - Maximum length of variable name is 255 characters. - The variable name should not be a Keyword. - It can contain only letters, numbers or the underscore character Ex : area, Area, AREA, sum, sum1, net_amount Variable types are 1) Numeric variable 2) String variable. 1)Numeric variable : It is the address of memory location that can hold only numeric constant. example : x = 124 net_amount = 23.55 sum1 = 1299 z = -45.78 2)String constant: It is the address of memory location that can hold only string constant. example: a = “RAJA” name = “JAMES BOND 007” y = “1234$”

3 Data Types Every application or program needs to process some data to generate the required output. All these data values need to be of different types. It can be classified into two types 1) Fundamental data types  Which is already defined by developer 2) User defined data  Which are created (or defined) by the user at the time of program or application writing. 1)Fundamental data types: VB provides the following fundamental data types are: –Byte –Boolean –Integer –Long –Single –Double –Currency –Object –Date –String –Variant

4 TypeStorageRange Byte1 byte0 to 255 Integer2 bytes-32 768 to 32 767 Long4 bytes-2 147 483 648 to 2 147 483 647 Double8 bytes -1.79769313486232E+308 to - 4.94065645841247E-324 for negative values; 4.94065645841247E-324 to 1.7976931348632E+308 for positive values Currency8 bytes -922 337 203 685 477.5808 to 922 337 203 685 477.5807 Decimal12 bytes +/-79 228 162 514 264 337 593 543 950 335 with no decimal and +/-7.922816251426337593543950335 with up to 28 decimal places

5 Data TypeStorageRange String (fixed length)length of string1 to 65 400 characters String (variable)length + 10 bytes0 to 2 billion characters Date8 bytesJan 1, 100 to Dec 31, 9999 Boolean2 bytestrue or false Object4 bytesany embedded object Variant (numeric)16 bytes any value as large as Double Variant (text)length + 22 bytes same as variable length string

6 Boolean data, represents data that can take only two values. These values are represented as either true or false. Variant is the default data type in VB. If the data type is not specified to a variable, then the variable is said to have variant data type. Declaration of Variables: (DIM statement ) VB allows you to declare and store values in variables. Syntax: DIM [As ] Examples: DIM name as string DIM id as integer DIM dob as date DIM sex as Boolean Example DIM name Here variable name is variant data type and can store any data suppose name = “Rama”  here name is a string type variable name = 125  here name is a integer type variable name = True  here name is a Boolean type variable name = 77.8  here name is a double type variable

7 Operators 1) Arithmetic Operators OperatorMeaningExampleResult ^Exponent2 ^ 38 *multiplication5 * 840 /division40 / 85 +addition2 + 68 -subtraction25 - 1510 &concatenation"Hi " & "There""Hi There"

8 Hierarchy of Arithmetic operators VB performs math calculations in strict order. The following image illustrates the order of operations

9 2) Comparison Operators (conditional /Relational)

10 3) Logical Operators OperatorMeaning ANDReturns TRUE if both Boolean expression are TRUE OR Returns TRUE if either Boolean expression is TRUE NOT Returns TRUE if Boolean expression is FALSE Or Returns FALSE if Boolean expression is TRUE

11 The Assignment Statement Once a variable is declared, it is ready to use. You store values in variables using the assignment statement( = is a assignment operator). Here is the format for the assignment statement: ItemName = constant / expression/ control’s propery ItemName can be a variable or a control property value. Here are examples of each in respective order: X = 10 sum = a * 0.14 / 2 Name =“Rajive” Label1.caption = “Enter First number”

12 MsgBox: It is one of the function. It is used to display customized messages to the users. Syntax: Variable = MsgBox(Prompt [,buttons][,title][,helpfile,context]) Here Prompt  is the message that is displayed Button  determine the type of buttons,

13 title  refers to the title of the message box. Ex: choice = MsgBox ( “Are you ready to print ?”, VbOkCancel,”Killikulam” ) Title Message Or choice = MsgBox ( “Are you ready to print ?”, 1,”Killikulam” ) Buttons

14 Ex : 2 s = 100 MsgBox ("The sum " & Str(s))

15 Input Box: This function displays a message box and allows the user to enter a value that your program can respond to. An input box is simply a message box with a field in which the user can type a value, such as a word or phrase that might answer a question you ask. Unlike message boxes, you cannot control which command buttons appear in an input box and you cannot place an icon in it as well. Syntax: Variable = InputBox (Prompt [, Title] [,Default] [,xpos][,ypos]) Here Prompt  is the message that is to be displayed Title  is the title of the Input box message box xpos, ypos  are the position where the InputBox is to be displayed. Ex:1 r = InputBox("Enter Radius", "Killikulam")

16 s = InputBox("Enter Your Sex", "Killikulam", "Mail")

17 Design a VB form to find area of circle Private Sub Command1_Click() Dim r As Double Dim area As Double r = InputBox("Enter Radius", "Killikulam") area = 3.14 * Val(r) * Val(r) MsgBox ("The area of Circle = " & area) End Sub


Download ppt "Creation of Variables with Numeric, alphanumeric, date, picture, memo data types Constant - A quantity that does not change during the execution of a program."

Similar presentations


Ads by Google