Solved variable or label

Posted on 2004-11-24
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
    LVL 8

    Accepted Solution

    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 85

    Expert Comment

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

    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??
    LVL 8

    Expert Comment

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: HTML5 Mobile App Development with PhoneGap

    PhoneGap can help you leverage your already existing HTML5, JavaScript, and CSS skills in order to create and deploy cross-platform mobile apps.This program comprehensively covers HTML5 mobile app development from top to bottom.

    Suggested Solutions

    Title # Comments Views Activity
    isEverywhere  challenge 19 48
    zeroMAx challenge 20 66
    commonTwo  challenge 63 68
    countPairs challenge 7 36
    Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
    A short article about problems I had with the new location API and permissions in Marshmallow
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    758 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

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now