Results 1 to 7 of 7

Thread: working with variables

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2000
    Location
    U.S.A.
    Posts
    50

    Question

    I've written a program that performs many calculations each time it is executed. This program uses several hundred variables (located in about 15 modules) each time the program is executed. I'm looking for a way to empty all the variables in each module each time the program is executed. This is necessary to ensure the modules are using current information provided by the user each time the program is executed. Currently, I am attempting this manually ( setting each value to zero or "") but I'm finding this too time consuming. Any help is appreciated. Thanks in advance.

  2. #2
    Guest

    well...

    well instead of using all those variables, you can use 1 variable and make an array out of it. for example in one of the modules just put:

    public MyVar(1 to 100) as Integer

    thats it! and everytime your program runs, all those variables will automatically be 0 because of the Integer part. i hope this is what you wanted, it seems like it should work. if you dont want an array of one variable then you must dim all your variables as an integer or whatever type you want, and by default they will be 0 or "".

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2000
    Location
    U.S.A.
    Posts
    50
    no sure about a few things hdem2....

    should this code always be (1 to 100) or does that depend on the number of variables (ie. 1 to 50) that i used in that particular module and the variables were declared as SINGLE or STRING vs as INTEGER...does that make a difference with your code?

  4. #4
    Addicted Member
    Join Date
    Jan 2000
    Location
    Sydney, Australia
    Posts
    196
    I think the area where you are running into problems is with any variables that are declared as private (or public) inside the module (that is, those variables declared between the very top of the module and you first function or sub in the module. These are visible to all functions in your module and stay resident between calls in your modules.

    Any variables declared inside an function or sub should be destroyed when the function or sub in the module finishes - so these shouldnt cause problems.

    So for starters you could just try to initialise only these types of variables (the ones outside any function or sub).

    A good thing you could do is (depending on how "modularised" you module is - that is are the functions within it called from all over the place from other modules or are they all basically called from one or so functions in that module which are in turn called from outside the module) put it all into a "Class Module". I'm not going to go into the full details of class modules - you should be able to pick the concepts up pretty quickly but feel free to ask for more info if you need it.

    Basically though with the class module you will put all your code (from your current module) in it (assume it is called clsABC). Then in your code when you need to use functions from that module you go:

    Code:
    dim theABC as clsABC
    set theABC = NEW clsABC
         :
         :
    theABC.someSubProc(1,2,3);
         :
    theABC.someOtherFunc("hi");
         :
         :
    set theABC = Nothing
    The usefulness of this is that when you go "set theABC = Nothing" it gets rid of all that memory that held the module and as long as you set the object to nothing after you are finished it and set it to a new clsABC before you need to use it again (like before and after the user enters more current info respectively) - the variables will all be initialised.

    I think hdem2's suggestions could work but it would mean that you have to place each variable at a specific index in the array and keep track of the index that each variable is at. Now this may not be a problem - but it may be very difficult to keep track of. And yes, the "100" in "1 to 100" would refer the the total number of variables you have...

    Any more questions about class modules then email me or post here.

    And if anyone knows of a simpler way than class modules i'd love to hear because i have had the same problem as DKing86 is having. But i do like class modules...

    [Edited by funkyd77 on 05-04-2000 at 12:27 AM]

  5. #5
    New Member
    Join Date
    May 2000
    Posts
    5

    Thumbs up

    Putting the code into a Class Module to clear all variables with 1 line of code (set test = nothing) is the best way to go as Funkyd77 stated.

  6. #6
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    I'm just stressing again how usefull class modules are in situations like this, if you do it with class modules you can even have 2 users going at the same time, or 3, maybe 4, as many as you like in fact.

  7. #7

    Thread Starter
    Member
    Join Date
    Mar 2000
    Location
    U.S.A.
    Posts
    50
    Thanks guys for all the good advice, I've taken the last few days to evaluate the feasibility of re-structuring the program using either a series of arrays or class modules. The array option wouldn't work because the variables in the modules are not all one type (some are string, some are single, and some are integers). Using class modules would require too much work at this point in the program since I am not at all familiar with using them and the program being pretty large. The next program I write will definately use class modules though, at least for the experience alone. So, I am still open for other ideas with this project and will check back from time to time. Thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width