devxlogo

Using Global Variables

Using Global Variables

Question:
I have visual basic 2.0 Hopefully not for long. If I make a button that does a funtion like this. n = n + 1 print nit gives me a 1. I then click the same button and it stillgives me a 1 every time. When I put n = n + 1 two or threetimes in the same buttons it does the adding. Is this something to do visual basic 2.0 or do I have to declare ita global varable or something?

Answer:
You do need a global variable. Define it in the declarations section of the form. Put the object list to (general) and the other list should say declarations. Dim N as integer in that section. Then, whenever or wherever you use the variable N, it will add or subtract from the same variable.

See also  How College Students Can Shape the Future of Tech Responsibility
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist