Variables or Classes? (1 Viewer)

mjdemaris

Working on it...
Local time
Today, 09:46
Joined
Jul 9, 2015
Messages
393
Referencing this page:

https://www.access-programmers.co.uk/forums/threads/tempvars-vs-type-variables.315649/

May I ask your opinions as to which may be a better option for my database?

I am building a program that several departments will use: for inventory, for ordering, logging repairs, logging problems with equipment, etc.

Currently we use several different databases but I would like to combine them into one, that way ordering parts/supplies and tracking costs is easier, among other possible benefits.

So, in one program, I use a User class module that I believe I found on this site. And I'm looking over it wondering what are the possibilities with a class? Then I find some tempvars, and remembered someone here had a distaste for them. And of course, I have a few global variables.

Add to that @NauticalGent posts an example of a global instance of a type? I have never used that before and don't really understand it.

The program opens with a hidden form, checks for inactivity behind the scenes (well, it will once it's done) and a menu screen appears allowing users to open the form(s) they need to use if they have permission to do so.

Generally, I call a function to get the user name and use that to determine what is available to the user.

Bottom line questions:

is a class worth using here?
would a global type be worthwhile? and how does that work? is it persistent throughout opening and closing of many forms?
would tempvars be more useful?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 00:46
Joined
May 7, 2009
Messages
14,176
a single Tempvars can only hold a a single scalar datatype.
on the other hand a Class can hold diverse datatype.

for me, it is easier to use Tempvars since you
will always "preceed" it with "Tempvars".

while class can be instantiated with any "name" variable
you like. you need to identify the root where the class
was instantiated to fully know what that class is about.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 12:46
Joined
May 21, 2018
Messages
5,506
I think @NauticalGent description is really good and that thread shows that user types and tempvars can serve about the same purpose. Tempvars are more tailored to Access because you can use them in queries unlike other variables to include user types. Also they never go out of scope even if an error is thrown.

Classes are far more robust. They can be composite composed of other classes. They usually have methods to do some kind of actions. They may have complex procedures for setting and returning properties. Tempvars and user types are pretty similiar, but classes are a complete different thing. From what you describe it sounds like you are just saving a few values "properties" of a single user so Tempvars would be sufficient, and as others have discussed Tempvars have some benefits that user types do not.
 

NauticalGent

CopyPaster of the First Order
Local time
Today, 12:46
Joined
Apr 27, 2015
Messages
4,180
I have started to use TempVars more frequently and I almost hate to admit that I have grown to like them.

Has others have said, the biggest benefit is their scope and that they can be used in a query.

Good post Majp...
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 11:46
Joined
Feb 28, 2001
Messages
20,882
The only biggie with TempVars is to remember that the value can only be a string or a number, not an object. IF that is OK with your needs, go the TempVars route. If you have to remember objects, you need a public variable of the appropriate object type.
 

MarkK

bit cruncher
Local time
Today, 09:46
Joined
Mar 17, 2004
Messages
7,840
I use a User class module that I believe I found on this site. And I'm looking over it wondering what are the possibilities with a class?
I recommend using classes if you can get your head around how. They are so simple and powerful and reuseable, and there is no project that wouldn't benefit from the order and organization that a class structure brings. But again, the biggest hurdle there is can you get your head around how OOP works, because it's like turning your current understanding of a coded solution inside out.
 

Cronk

Registered User.
Local time
Tomorrow, 03:46
Joined
Jul 4, 2013
Messages
2,546
I agree with using classes for database entities and use TempVars for unrelated variables. I previously posted some code to generate a class based on the field names of any table. With classes you get full intellisense on all the class properties and methods.
 

mjdemaris

Working on it...
Local time
Today, 09:46
Joined
Jul 9, 2015
Messages
393
Thank you @MarkK and @Cronk for throwing a wrench in going with Tempvars! :)

I think I will start with the TempVar approach, as it fits the style of coding I have been doing. However, I would like to learn more and possibly convert this current program to a OOP...maybe.

I will have a look at the links you all have shared as well.

One more thing: Do I need to consider memory usage when working with tempvars versus other variables and such?
 
Last edited:

Users who are viewing this thread

Top Bottom