By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,222 Members | 1,132 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,222 IT Pros & Developers. It's quick & easy.

why use the word public in a function

P: n/a
Hi everyone

Why do you use the word public in a function, when the function is fully
accessible without the word public in front of it.

I read the help, but did not really get it.

Cheers

Nicolaas
---
Please immediately let us know (by phone or return email) if (a) this email
contains a virus
(b) you are not the intended recipient
(c) you consider this email to be spam.
We have done our utmost to make sure that
none of the above are applicable. THANK YOU
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.690 / Virus Database: 451 - Release Date: 22/05/2004
Nov 13 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
If the function is in a standard module (a module in the module tab of the
main database window) it is Public by default. So, if you don't say Public,
it still is. However, relying on defaults will get you into trouble sooner
or later when you forget exactly what the default was. It is much easier to
read, follow, and remember what something is supposed to do if it is spelled
out. This is the same reason for including lots of good, thorough comments
in your code. Try going back a year later and reading something and you'll
understand.

--
Wayne Morgan
Microsoft Access MVP
"WindAndWaves" <ac****@ngaru.com> wrote in message
news:wN*******************@news.xtra.co.nz...
Hi everyone

Why do you use the word public in a function, when the function is fully
accessible without the word public in front of it.

I read the help, but did not really get it.

Nov 13 '05 #2

P: n/a
Thanks for your answer Wayne.

Why would you ever have a function that is not public and how can the
default setting change????

Should I go through all my codes and make them all public???

Thank you once more for your answer

Nicolaas
---
Please immediately let us know (by phone or return email) if (a) this email
contains a virus
(b) you are not the intended recipient
(c) you consider this email to be spam.
We have done our utmost to make sure that
none of the above are applicable. THANK YOU
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.690 / Virus Database: 451 - Release Date: 22/05/2004
Nov 13 '05 #3

P: n/a
WindAndWaves wrote:
Thanks for your answer Wayne.

Why would you ever have a function that is not public and how can the
default setting change????
Easy, code on a form is private to the form (usually).

You can't change the default.
Should I go through all my codes and make them all public???
If you want to follow good practice, perhaps you should :)
Thank you once more for your answer

Nicolaas

--
regards,

Bradley
Nov 13 '05 #4

P: n/a
rkc

"WindAndWaves" <ac****@ngaru.com> wrote in message
news:qi*******************@news.xtra.co.nz...
Thanks for your answer Wayne.

Why would you ever have a function that is not public and how can the
default setting change????


When you have a public function that does something so involved that
you have decided to spread the implementation over more than one
sub or function. There are times when the helper functions are only
meaningful when called from the public function. To insure that the
helper functions can't be called from outside the module or object they
reside in they would be declared private.
Nov 13 '05 #5

P: n/a
Bradley wrote:
WindAndWaves wrote:
Thanks for your answer Wayne.

Why would you ever have a function that is not public and how can the
default setting change????

Easy, code on a form is private to the form (usually).

You can't change the default.

Should I go through all my codes and make them all public???

If you want to follow good practice, perhaps you should :)


Are you joking?
Thank you once more for your answer

Nicolaas


Nov 13 '05 #6

P: n/a
Bradley wrote:
WindAndWaves wrote:
Thanks for your answer Wayne.

Why would you ever have a function that is not public and how can the
default setting change????

Easy, code on a form is private to the form (usually).

You can't change the default.

Should I go through all my codes and make them all public???

If you want to follow good practice, perhaps you should :)


Are you joking?
Thank you once more for your answer

Nicolaas


Nov 13 '05 #7

P: n/a
I have private functions that I don't want to use except when
called from another function in the same module. Typically
this is because I want handle exceptions seperately, or because
I want to translate the parameter list.

Private functions are also used when you want to handle the
initilisation and use of local data seperately. This is the
reason that functions in a Form Module default to private.

For example, you may have a private sub:
===========================
private sub mysub(a)
select case a
case "1": me.edtName = "fred"
......
===========================

That private sub may be a sensible way of orgainising code,
but it makes no sense at all outside of the context of the local
data.

Or, an example of exception handling and parameter translation:

===========================
public function myfn(mystring) as double
on error goto standard_exception
dim n

n = val(mystring)
myfn = myPrivateFunction(n)
exit function
standard_exception:
.....
============================

(david)
http://www.hyphenologist.co.uk/killf...filefaqhtm.htm

"WindAndWaves" <ac****@ngaru.com> wrote in message
news:qi*******************@news.xtra.co.nz...
Thanks for your answer Wayne.

Why would you ever have a function that is not public and how can the
default setting change????

Should I go through all my codes and make them all public???

Thank you once more for your answer

Nicolaas
---
Please immediately let us know (by phone or return email) if (a) this email contains a virus
(b) you are not the intended recipient
(c) you consider this email to be spam.
We have done our utmost to make sure that
none of the above are applicable. THANK YOU
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.690 / Virus Database: 451 - Release Date: 22/05/2004

Nov 13 '05 #8

P: n/a
The Public keyword shows that you intended the procedure to be Public rather
than you forgot or didn't know what the implications are of a procedure
being Public.

In a module a Public procedure is in scope (accessible) to all other code in
the project, a Private procedure is in scope for other code in the module.

The best way to write code is in procedures where the code in the procedure
is to some extent atomic i.e. the code does something and that's all it
does, this helps enormously in the debugging process.

Say for example you wanted to connect to a database using ADO and retrieve a
recordset from the ADO source. You could write a function which takes all
the necessary steps in one big lump or, you could break the process down
into smaller chunks and write those smaller chunks in separate procedures.
Then so long as your sequence of calling those procedures is correct you
just have to worry about each procedure in isolation.

So you would
write a private procedure to get the connection string
write a private procedure to set up the ADO connection
write a private procedure to set up the ADO recordset
write a private procedure to retrieve the records

If you then wrap these private procedures in a public procedure you can call
the public procedure from outside the module and have a high level of
confidence that it will work, but even if it doesn't, because the code is
broken down it is easier to find where the problem is and correct it.

--
Terry Kreft
MVP Microsoft Access
"WindAndWaves" <ac****@ngaru.com> wrote in message
news:wN*******************@news.xtra.co.nz...
Hi everyone

Why do you use the word public in a function, when the function is fully
accessible without the word public in front of it.

I read the help, but did not really get it.

Cheers

Nicolaas
---
Please immediately let us know (by phone or return email) if (a) this email contains a virus
(b) you are not the intended recipient
(c) you consider this email to be spam.
We have done our utmost to make sure that
none of the above are applicable. THANK YOU
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.690 / Virus Database: 451 - Release Date: 22/05/2004

Nov 13 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.