Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Importance of Private/ Importance of type...

Posted on 2004-09-02
Medium Priority
Last Modified: 2010-05-02
hello experts, this is maybe a juvenile type of question, but here goes...

i'm wondering what the effect of using Private versus Public function has on the compiled EXE... does using Private make the program smaller, or use less memory?  or does using Public when not needed somehow increase the possibilty of the program being hacked... somehow using the program to gain access to something they shouldn't be allowed?

also along the same lines... i'm wondering if declaring your variables as a specific type will effect the efficiency of the program... does declaring everything as varient type use more memory?  does declaring a variable as Long when it could have been Integer use more memory once my EXE is compiled?
Question by:RobK6364
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 10

Assisted Solution

kiranghag earned 100 total points
ID: 11969740
>>does declaring a variable as Long when it could have been Integer
>>use more memory once my EXE is compiled?
but this will be noticeable only when you use huge number of variables...or larger arrays
long variables require double the space than an integer.
LVL 101

Assisted Solution

mlmcc earned 100 total points
ID: 11970146
>>does using Private make the program smaller, or use less memory?  
I don't think so.  Public and Private have to do with the visibility of the function from other forms or modules.

>>using Public when not needed somehow increase the possibilty of the program being hacked
I don't think so.  Public is really only used by the compiler.  It might if you  provided your program in a library that someone could link in to their program and try to use it but they would still need to know function names and the like.


Assisted Solution

_agj_ earned 100 total points
ID: 11970683
variant types DO use up a lot of memory....use them ONLY when specifically required.

the same goes for long etc.

As for Private/ only affects visibility in code, not the exe efficiency or size.
It might affect it if u are compiling to p-code. But if u compile to native assembly, there is no reason u shud have any difference.

Regarding hack-ability, declaring something as public only makes it callable...which makes it less secure/exposed to the outside world. In that sense, expose as public only your required functions. Everything that is supposd to be 'internal' and 'non-exposed' should be private.
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 11970938
>>>>does declaring a variable as Long when it could have been Integer
>>>>use more memory once my EXE is compiled?
on the other hand, performance wise, using long integers (32 bits wide, "LONG" in VB) is more efficient than using short integers (16 bits wide, "INTEGER" in VB). This is because almost all processors these days are 32 bit, and internally have to convert a 16 bit integer to a 32 bit integer before processing it. Difference in VB is marginal however.
LVL 76

Accepted Solution

GrahamSkan earned 200 total points
ID: 11971027
The reason for having both Private and Public is for the benefit of the programmer. It would be possible to have all your variables (and procedures) declared as Public, but you could easily lose track of what is modifying the value of public variables. So, as a rule of thumb, keep the scope of variables a small as possible, if necessary passing them into procedures as parameters. This does use more resources, but the effect on performance would only be marginal.

I take the same attitude to declaring the type of variables. You can save a bit of time by not declaring them, but if do you declare your variables as their intended type, then you will know sooner when you have made an error. I always have Option Explicit in the Decalarations section of the code. You can ensure that it's put there automatically: Tools/Options..., Editor tab, Require Variable Declaration checkbox.

Author Comment

ID: 11993229
thanks for all the replies... most of my program is "optimized" with the correct declarations..but going back finding and changing things that already work but could be "optimized" would be a pain... so basically i just wanted to get a feel for if that was a very important thing to do...

and although there seem to be some varying opinions, it seems to not be any huge concern as long as my entire program isn't all variant, which it's not.

not sure who to give the points to... so i'll split em up
LVL 101

Expert Comment

ID: 11993573
Glad I could help


Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

670 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