# [SOLVED] Global variables in VB Express 2010?



## Mugsy323 (Jun 25, 2010)

I used to do a lot of VB6 programming, but since Win7 doesn't like VB6, I'm trying to learn VB 2010 Express, which so far is a PIA (Pain in the "Butt").

After hours of figuring out how to read a text file from a _relative_ (not hard) path (you must put the file in your "Debug" folder), I'm now trying to figure out how/where to declare "global" variables that can be read from any procedure.

You _used_ to be able to simply Dim your variables in the "Declaration" section above all procedures, or add a standalone Module, but that doesn't work anymore with Express. MS's help system is worthless. So I'm stuck. :4-dontkno

This is just stupid. I feel like a newbie instead of someone who has been programming for over 25 years. Please help.


----------



## Mugsy323 (Jun 25, 2010)

*Re: Global variables in VB Express 2010?*

Okay, I figured it out. What a pain.

If you're creating a single-form app, you can add "global" variables by declaring them _beneath_ the top most Public Class of your form (the Actions drop-down will change to "(Declarations)":

```
Public Class Form1

    Dim strMyVar As String  ' Variable will be global to *this* form.

    Public Sub Form1_Load(...
...
```
To add a new Module, in the "Solution Explorer" (??? Components?) window, right-click on the project name and "Add" the new Module. Variables declared there will travel between forms.

A tiny bit different from VB6. In many ways, VB2010 is more like C. What a pain this is going to be.


----------



## Ninjaboi (Dec 27, 2010)

*Re: Global variables in VB Express 2010?*

Thank you for providing the solution to your problem Mugsy323. Glad that it was solved ( and by the same person who asked, so it shows your dedication to your problem ).


----------

