Question

With the use of relevant examples discuss the concept local and static variables in Visual Basic...

With the use of relevant examples discuss the concept local and static variables in Visual Basic (OOP and EDP)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

Before discussing about the concept of local and static variables,we will discuss a little about the variables.

So, a Variable in Visual Basic is used to store the values that are needed to perform the calculation in the program.

A variable along with the unique name and data type is used to store the values .

We declare the variables to specify the properties of the statement in the program.A variable can be declared in many many like: as a Local variable,Static variable and the Global variable.

  • LOCAL VARIABLE:
    • The variable that is declared inside or within the program that contains the procedure or the function of the program is known as the Local variable.
    • In the program the local variables exist only upto the execution of the procedure or the function in which the variable is declared.
    • After the execution of the procedure or the function the value of the local variable is not longer exist and all the memory the is used by the variable is get free and can be used again for another procedure in the program,.
    • To declare a variable to be the local variable in visual basic the keyword DIM is used.
      For example: Dim a As Integer

                           In the above example the variable a is declared as the local variable which contain a integer value.

  • STATIC VARIABLE:
    • The variable which are declared to specify more than one local variables in the procedure and the function in the program so that it value is retain even after the executing of the procedure and the function.
    • The static variable exit as long as the procedure is exist in the program.
    • The Static variable creates only the single copy of the variable for the whole program.
    • To declare a variable to be static the Static keyword is used.
    • Also the static keyword is only used with the local variable,it cannot be used with the global variable.

                      For Example:

                          Function counter(ByVal count As Decimal)

                             Static TotalCount As Decimal=0

                                   TotalCount +=count

                            Return TotalCount

                            End Function

In the above example the TotalCount variable is used as the Static variable which is started from the 0 .every time whenever we enter the counter function the TotalCount variable will contain the latest value that is calculated.

Add a comment
Know the answer?
Add Answer to:
With the use of relevant examples discuss the concept local and static variables in Visual Basic...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT