Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 136,582 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,926 people online right now. Registration is fast and FREE... Join Now!




Simple Variable question

 
Reply to this topicStart new topic

Simple Variable question, Storing variables

Qball522
6 Oct, 2008 - 10:12 AM
Post #1

D.I.C Head
**

Joined: 6 Oct, 2008
Posts: 54

Hello all

First I would like to say TY for this cool site. Much thanks to all the guys and gals on here, I have learned a few things already just from the 10-15 minutes I have been reading over some posts.

Ok on with my easy question, please no laughter I am very new to VB, I might even go as far to say I am new to programming in general.

I was wondering how one goes about declaring a variable throughout the program. Not sure the technical name for this I am sure there is one. Basically I want to set a variable and have different button clicks manipulate this number and store it again to be available for other interaction.

I know there has to be something out there, If at all possible I would like it to be as simple as it can get for this.

Thus far the only way I have found to pass a variable from one Sub to the next is to output the variable in a Label and then call on that Label in the next.


I am stumped... I watched a vid on a timer and he declared the variable outside any sub form and it worked... I tried it and same result, it works.... So i would like to say I am sorry for the dumbest question.

Thank you in advance.

This post has been edited by Qball522: 6 Oct, 2008 - 11:14 AM
User is offlineProfile CardPM
+Quote Post

jaakko
RE: Simple Variable Question
6 Oct, 2008 - 11:17 AM
Post #2

New D.I.C Head
*

Joined: 26 Sep, 2008
Posts: 21



Thanked: 1 times
My Contributions
QUOTE(Qball522 @ 6 Oct, 2008 - 11:12 AM) *

Hello all

First I would like to say TY for this cool site. Much thanks to all the guys and gals on here, I have learned a few things already just from the 10-15 minutes I have been reading over some posts.

Ok on with my easy question, please no laughter I am very new to VB, I might even go as far to say I am new to programming in general.

I was wondering how one goes about declaring a variable throughout the program. Not sure the technical name for this I am sure there is one. Basically I want to set a variable and have different button clicks manipulate this number and store it again to be available for other interaction.

I know there has to be something out there, If at all possible I would like it to be as simple as it can get for this.

Thus far the only way I have found to pass a variable from one Sub to the next is to output the variable in a Label and then call on that Label in the next.


I am stumped... I watched a vid on a timer and he declared the variable outside any sub form and it worked... I tried it and same result, it works.... So i would like to say I am sorry for the dumbest question.

Thank you in advance.

You can declare a variable at the top of a frame or module like this:

Private nL as integer

and it is visible everywhere in that frame or module but not in other
frames or modules.
If you want to declare a variable to be visible everywhere in the
project, do this

Public nL as integer

If you have declared it in frmMain you can see it everywhere in
your project by writing
frmMain.nL
User is offlineProfile CardPM
+Quote Post

akhileshbc
RE: Simple Variable Question
6 Oct, 2008 - 11:22 PM
Post #3

D.I.C Head
Group Icon

Joined: 26 Sep, 2008
Posts: 177



Thanked: 3 times
Dream Kudos: 50
My Contributions
If you want to use a variable throughout in any part of a form, then declare the variable in the top of the Code window(ie. beginning of the code)

If you want to use a variable throughout the program, for example the variable that stores the user name, then create a module by: Project menu > Add Module
Then declare the variable as public inside the module:
eg:

Public usrName as string
User is offlineProfile CardPM
+Quote Post

Qball522
RE: Simple Variable Question
7 Oct, 2008 - 05:06 AM
Post #4

D.I.C Head
**

Joined: 6 Oct, 2008
Posts: 54

TY much.

For the longest time, about 2 days, I could not get it to work, I don't know what I was doing but it wasn't working for me. I think what I was doing was loading the form and trying to declare public variables there.

So again TY for the help.
User is offlineProfile CardPM
+Quote Post

akhileshbc
RE: Simple Variable Question
7 Oct, 2008 - 05:31 AM
Post #5

D.I.C Head
Group Icon

Joined: 26 Sep, 2008
Posts: 177



Thanked: 3 times
Dream Kudos: 50
My Contributions
Welcome smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 12:38AM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month