| Variables |
| Any programming language requires to store values temporarily for different purposes like calculations Adding, multiplying etc.Visual Basic gives the need for variables. You can think of variable, a place in memory of computer for an unknown value. |
| For example when you call someone, then you call him /her by name, like that every variable has name. |
| Variable name is the word which you use to refer to the values that the variable contains. |
| VARIABLES:- Naming convention |
| There are different rules for assigning names to variables ,these are as follows: |
| A variable name must begin with a letter. |
| For example: |
| 6date - Invalid variable name |
| date6 - valid name |
| Two variables must not contain the same name. |
| It can not contain a dot or space. |
| For example: |
| Num2 - Valid variable name |
| Num.2 - Not Valid |
| Num 2 - Not Valid |
| A variable name must not exceed 255 chracters. |
| A variable name must not contain any special characters like %, $ , * , & ,! ,@ etc. |
| For example: |
| @num, num$r are not valid variable names. |
| Variable:-Declaring |
| The term declaring a variable means that the memory is allocated .This memory will be referred by a name decided by the programmer.The specific data type decides the amount of memory allocated. |
| You can declare a variable with a Dim statement by giving a name for the variable according to rules of naming conventions. |
| Syntax: Dim variablename as Datatype |
| Example: Dim a as integer |
| In above example 'a' is variable name and integer is the data type. |
| Rules for declaring variables: |
| (i) Declaring a variable using the word Public makes it available throughout the program. |
| (ii) Declaring a variable using the word Static keeps it's value preserve until a procedure ends. |
| (iii) Declaring a variable in the declaration section of the form makes it available to all procedures in that module. |
| For example: |
| Let us consider the variable 'var1 '. An integer variable 'var1' is declared. At the same time memory is allocated for the variable. |
| The variable is given value 20 during the running state of the program. This value is stored in the given memory location. |
| This process is shown in figure: |
![]() |
Wednesday, February 25, 2009
Variables
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment