473,383 Members | 1,953 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Public Variables in Module1

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.
Nov 21 '05 #1
3 1698
Hi patang,

Have a read of this blog entry I wrote that goes over this:

http://agoossens.blogspot.com/2005_0...s_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:
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.

Nov 21 '05 #2
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
Nov 21 '05 #3
"patang" <pa****@discussions.microsoft.com> schrieb:
Module Module1
Public connectionstring = "provider=Microsoft.Jet.OLEDB.4.0;data source="
+
Application.StartupPath + "\mydatabase.mdb;"


In addition to the other replies: It's recommended to use the '&' operator
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/>

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: jeff | last post by:
Hi, what is a good way to implement public common constants. like what we do in a common header file in C++. jeff
0
by: J.K. Bach | last post by:
I have an ASP.NET project wherein module-level functions are declared and implemented within the aspx page <%= %> tags. This was working fine before, but now that I have recreated the project to...
8
by: Floris van Haaster | last post by:
Hi All! I have a question, i have a web application and I store some member information in a variable i declared in a module like: Public some_info_variable as string in module1.vb But...
1
by: Chris Thunell | last post by:
I need to loop through a public folder on our exchange server and get some information out of each record... I have the following code, but I can't seem to figure out how to reference the public...
2
by: | last post by:
See This Code ======================================================= ..method private specialname rtspecialname static void .cctor() cil managed { // Code size 52 (0x34) .maxstack 8...
4
by: ST | last post by:
From Form1 I call a public sub in a module. The sub writes on Form1. Problem: the call creates a new Form1 and writes on it, instead of writing on the one already shown Form1. I have tried to...
11
by: prefersgolfing | last post by:
I'm trying to find on MSDN, or someplace, that speaks to variables being public or private by default. Anyone know where? Thanks.
5
by: Henry Jones | last post by:
I posted in dotnet.general but I think this is a better place to post a VB question. I created a module in VS 2005 - Visual Basic Windows Project. I declared two strings public Public...
4
by: Jim Carlock | last post by:
I've been using global to expose variables. However, I noticed the following... (1) global seems to use the nearest declaration. For example, // module1.php $sMyString = "Hello World.";
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.