|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Public Variables in Module1Very simple question.
I have a project with multiple forms and a Module1. In Module1 I have written the connectionstring: Module Module1 Public connectionstring = "provider=Microsoft.Jet.OLEDB.4.0;data source=" + Application.StartupPath + "\mydatabase.mdb;" End Module In Form I am using this "connectionstring" form. Ok..now here is the question. How come this variable is available (automatically) in other forms even though I haven't imported Module1 in those forms? Thank you in advance. Hi patang,
Have a read of this blog entry I wrote that goes over this: http://agoossens.blogspot.com/2005_04_01_agoossens_archive.html Check the paragraph titled "Members of a module are scoped to the surrounding namespace of their module." I've been having issues with blogger lately so I've given up any form of blogging :p Members of modules are scoped to their surrounding namespace. So, as long as you import the namespace of the module you can access it's members automatically. "Under-the-hood" the VB.NET compiler applies the StandardModule attribute to your Module. When you compile code that calls the members of this module, the VB.NET compiler automatically replaces them with their properly qualified versions. IE, this: --- Console.WriteLine(connectionString) --- Becomes this: --- Console.WriteLine(Module1.connectionString) --- Hope that helps, -Adam. patang wrote: Show quoteHide quote > Very simple question. > > I have a project with multiple forms and a Module1. In Module1 I have > written the connectionstring: > > Module Module1 > Public connectionstring = "provider=Microsoft.Jet.OLEDB.4.0;data source=" + > Application.StartupPath + "\mydatabase.mdb;" > > End Module > > In Form I am using this "connectionstring" form. > > Ok..now here is the question. How come this variable is available > (automatically) in other forms even though I haven't imported Module1 in > those forms? > > Thank you in advance. > > Patang,
A form is just a class in your project what is instanced as one or more objects. You can use one form class to create more form objects. A module is an forever shared class in your project. The name for shared in C derived languages is static. The shared declared members are every where usable in a project and will not been destroyed. I hope this helps, Cor "patang" <pat***@discussions.microsoft.com> schrieb: In addition to the other replies: It's recommended to use the '&' operator > Module Module1 > Public connectionstring = "provider=Microsoft.Jet.OLEDB.4.0;data source=" > + > Application.StartupPath + "\mydatabase.mdb;" for string concatenations in VB.NET. 'System.IO.Path.Combine' can be used to combine path and file name. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/>
cint and int32.parse
Hide unwanted properties. Can't destroy Excel Process; tried Just about everything! NullReferenceException when setting to array list Connection pool problems My application exits after handling an ApplicationException Error after removing row and then adding new row to datatable How to copy files from desktop to web server Naming convention for objects Re: Freeze Column in DataGrid |
|||||||||||||||||||||||