Sunday, February 5, 2017

Important Concepts Of Variables in VB and Examples


   Variables                   
vbsoftwarecode


  If you are a code maker or interested in making code you must have to learn about variables. 
Variables are very used and used in any programing language. It is like a common language name that we use frequently. The concept of variables are same in all language. 

Variables are assigned name for any name or any values. They are used for visualizing another values.Variables are assigned space in a memory for any related value. Variables are changing values for which we can change any values if necessary. 

Variables are used to assigned values and retain the value from the variables we have defined. 
For example. 
vbsoftwarecode

In mathematic we use suppose for getting values. In the same way variables are also used for getting and assigning values.  
In simple 

if   x=3 and y = 4 then 
find  z = x+2y 

In above , x and y are variables , but the equations are same. The result may varies if variables changes. But the assigned values are processed and new value is provided in variables in Z. 

Like wise , there are different types of variables. 
In Vb 6.0 we are not compulsory to define variables type but in ..................
vb.net it is compulsory to define with data-types. 

we define variables as data-type are defined .


Data-type are a formated data-type for which we assign a value in a variables. Data type are format of data we want to get or input data on the variables.
 
There are different data types. 
1. String data type
2. Numeric
3. Date 
4. Boolean
5. Object etc.

We define variables according to its value data-type.  

Defining data for string value .

        Dim str as string 

Defining data for numeric value.

       Dim Int as Integer 

We can define variables for three groups .
 
vbsoftwarecode
First one is for private group. In this we define variables for only for a block of code. It means it is used for only defined group of codes. It cannot be accessible and used from outside its own block of code. 
For example :
---------------------------------------------------
Private Sub abcd() as long 

Dim int as integer 

int = 25 

End Sub
-----------------------------------------------------

In above code int variable is used in only inner from private and end lines. It cannot be used outside the block of code. 


Second type of group is on the public for only one form. 
It is defined outside the private area of the block of code or above the codes. 
It is accessible to all private area of the block codes but not applicable outside the form area,
It is mostly defined when one value is necessary to other block of code in the same form

For example , 
-----------------------------------------------------
Dim abcd as integer 

Private sub add_click ()

abcd = 300

End sub 

private sub get_click()

msgbox abcd

End 

---------------------------------------------

In above example we have assign variables above block of code. In the add block of code we have passed the value of variables and in the get block we have retrieve the value that is assigned value in the variables. 

Thank you for your time.


Best regards

Any Question Please make me known.
Narayan Arjyal 
Nepal 











 



No comments:

Post a Comment