Click here to Skip to main content
15,891,853 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good morning everyone.

I am battling with what may be something simple.
I have a number of programs that open any of 4 Access databases. Each of programs contains duplicate code to establish the connection string to the applicable database or databases (one connection at a time).

For the first time in my development life I am attempting to write a Class Library in order to eliminate the need to rewrite (or copy and paste) all this code.

Part of the requirement is to check if the database exists before establishing the connection.

If it does not then show a message to that effect and terminate the Class Library.

And this is where the wheels come off.

It appears that an END statement does not work in a Class Library.

Is there a way to terminate a Class Library prematurely or do you change the logic and just let the process fall through to a logical end?
Posted
Updated 30-Oct-14 23:48pm
v2

1 solution

I'm not sure what you mean by "terminate a Class Library prematurely", but you may find http://www.csunit.org/tutorials/tutorial6/[^] useful.
 
Share this answer
 
Comments
Darrell de Wet 31-Oct-14 7:06am    
Hi Richard. Thanks for the response.
I'm not the most experienced programmer and it often shows in the poor way that I ask questions.

If I debug and hit F11 to step thru each line of code I can follow the thread the program follows. If the program says eq, OpenDBConnection("Commercial") and OpenDBConnection is the Class Library and Commercial is the database I wish to open then debug will lead me into the code in the Class Library.
One of the first things the the Class library must check is if the database exists.
eg. If NotExists ...... path & "Commercial" & ".accdb" then
END
endif
in other words 'prematurely terminate the class library' and return to the next line of code in the form. rather than go to the code within the class that actually establishes the connection string.

Hope i'm making a little more sense.

Thanks
Darrell
Richard MacCutchan 31-Oct-14 12:43pm    
You just need a return statement, see http://msdn.microsoft.com/en-us/library/2e34641s.aspx. It always helps to learn the basics of a language first.
Darrell de Wet 31-Oct-14 13:09pm    
Your time and effort is much appreciated. Thanks for the answer.
I have, by the way learned the basics (and continue to learn more daily) - have used RETURN in many Private Functions, but as I said in the original question I have never written a Class Library and in this instance RETURN never occurred to me.
Richard MacCutchan 31-Oct-14 13:17pm    
There is nothing inherently special about a Class library; it is just a collection of methods the same as those in any other piece of VB code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900