vb.net variable or label

Posted on 2004-11-24
Medium Priority
Last Modified: 2010-04-17
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.

Question by:peanut1010
  • 2

Accepted Solution

AaronReams earned 120 total points
ID: 12668450
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,
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 12669626
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


Author Comment

ID: 12671152
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??

Expert Comment

ID: 12671197
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Make the most of your online learning experience.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Loops Section Overview

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question