John Clark
John.Clark at niagaracounty.com
Thu Feb 13 12:11:00 CST 2003
First for Susan Klos...No problem! The more the merrier! Next...Once again, I would like to thank everybody for their input. I really like John Colby's thinking on this one...especially with the reports example. I have started using functions and just wanted to make sure that there was no major reason that I should be using subs. My reason for using functions...I did not need a return value...was that I could easily see what was an event and what was a function that I created, by quickly scanning the code. So, unless anybody comes up with a major advantage of using the subs, or a major disadvantage of using functions, I am going to continue with the function way of doing things. Thanks again! John W Clark >>> jcolby at colbyconsulting.com 02/13/03 12:09PM >>> John, Functions can return a value, subs can't. It is often useful when you move to this method of programming to return a value that says that the function accomplished it's purpose. IOW, perhaps the function is supposed to build a report. The report is going to (in this example) be saved as a hardcopy on the network somewhere. There are all kinds of things that could prevent the report from being generated, or being saved. So the function returns a True if the report process worked, or a false if it didn't. I tend to do something like: function BldReport() as Boolean On Error goto BldReport_Error BldReport = false 'Specify a false value up front. The process must work to be set true Do my report process, try to store etc. . . BldReport = true Exit_BlDReport Exit function Err_BldReport 'handle errors here resume Exit_BldReport end function As you might surmise, the function tries to build the report. If anything goes wrong the error causes control to vector to the error handler where whatever you decide to do to handle errors is done. When it is done, control resumes at the exit. The statement that sets the function name true is never executed, so the function returns false. If no error occurs, processing just continues down the function and eventually sets the function return value true and exits. Therefore the code that tries to generate the report can now do something like: if BldReport() then 'This is good, continue else 'this is bad, notify the user, log the error etc. endif So, to re-iterate, functions can return a value. Even if they normally wouldn't it is often useful to use that ability to return the fact that the function succeeded in whatever it was supposed to do. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: accessd-admin at databaseadvisors.com [mailto:accessd-admin at databaseadvisors.com]On Behalf Of John Clark Sent: Thursday, February 13, 2003 11:20 AM To: accessd at databaseadvisors.com Subject: [AccessD] Function vs Sub I recently smartened up and started using fuctions in my code, and I've got what may be a very dumb question...should I be using "functions" or should they be "Public Subs" or ?????? What is the difference. I apologize if I am lowering the intelligence quota today, but I just haven't come across this and I don't want to go down the wrong path. _______________________________________________ AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com _______________________________________________ AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com