vb.net variable or label

I was wonder I have a program I am working on that does a hit on a database and I need to store certain data for later actions.

Example database pulls in there age, in my program there might be a button that does a age calculation, I would need to have the program remember what was 1st pull in order to avoid another fetching.

I was keeping things in variable:

dim age as integer

when the database first fetches the age it dumps it to the variable age. then when the user hits the button for age calculator it looks at the variable age. Should I do it this way or should I have it say to the mdiparent in a hidden label on a hidden statusbar panel., I have about 5 things I need to store for later use.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi Peanut,

If you only need to store 5 integer values you should use variables like in your example.   It doesn't make sense to store them in a hidden label or status bar panel if they are only used for calculations and never displayed to the user.   One of the reasons for this is that labels and panels consume more system resources than integer variables.  Your program will be smaller and more efficient if you optimize resource use.

Hope this helps,

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mike TomlinsonMiddle School Assistant TeacherCommented:
If you are only dealing with one record at a time then use variables as you already are and AaronReams suggests.

If you need to store this data for more than one record and don't want to retrieve it form the database repeatedly then create a class to hold the info.  Then you can create mulitple instances of it and store them in an ArrayList or something.

    Public Class someClass
        Public age As Integer
        Public someOtherValue as String
        ' etc...

    End Class

peanut1010Author Commented:
AaronReams, wonder if it is a string

Like one of the other piece of data I am need to store for later use is the vendors address.  What i am doing is in one part of my program A  user can hit a button on the form and it takes the address and queries a database for the record matching.

This is ok right? because it uses less resources???



I usually store my variables in a module:

sub module
public age as integer

end sub

what would a class do and is what I am doing wrong??
Exactly.  If you don't need the user to see or modify the vendors address there is no need to use a label or textbox control.   You can just save it to a string variable.

Public myAddress as String

Also if you declare your variable within a sub procedure, it is a local variable.  This means that if you exit that sub procedure and then enter/call it again later the variable will no longer contain the old value.  Also you cannot access that local variable from a different sub procedure.

Hope this helps.  Good luck -Aaron
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.