Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > Pro VB.NET 2002/2003
|
Pro VB.NET 2002/2003 For advanced Visual Basic coders working .NET version 2002/2003. Beginning-level questions will be redirected to other forums, including Beginning VB.NET.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 1st, 2005, 04:12 AM
Authorized User
 
Join Date: Apr 2005
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to EricJ
Default Modules and public variables

Look at this pieace of code:

Option Explicit

Imports System.Data.SqlClient

Module Globals

    Public lConnection As SqlClient.SqlConnection

End Modules

Now I'm trying to refer to "lConnection" in a class called Data.Access which will later be used in my main application. When I Import the namespace as 'Globals' in my Data.Access Class I should be able to access the "lConnection" variable as it is publicly accessible to other classes or am I interpreting it incorrectly?

EricJ

 
Old July 1st, 2005, 08:16 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I don't know if this will help at all, but I dug this out of the MSDN documentation after some searching:
Remarks
Modules are a reference type similar to classes, but with some important distinctions. The members of a module are implicitly Shared and scoped to the declaration space of the standard module's containing namespace, rather than just to the module itself. Unlike classes, modules can never be instantiated, do not support inheritance, and cannot implement interfaces. A module can only be declared in a namespace and cannot be nested in another type.

You can have multiple modules in a project, but members with the same name defined in two or more modules must be qualified with their module name when accessed outside of their module.
Source: http://msdn.microsoft.com/library/en...akeyModule.asp

-Peter
 
Old July 1st, 2005, 08:49 AM
Authorized User
 
Join Date: Apr 2005
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to EricJ
Default

Thanx Peter!

I looked at the exact same documentation a while ago, but still face the same problem.

I Visual Basic 6 it was easy to create a new ActiveX DLL, add a module, compile it into a DLL and add the reference, but I'm having huge problems inplementing a similar case in VB.Net.

I copied the Module 'Globals.vb' into every project in my solution and that works fine, but still doesn't allow me to create one instance (it can not be instantiated) of the module and calling it up in my other projects.

I will browse around the net some more!

I also face another problem when creating a new property which should be 'WriteOnly':

Public WriteOnly Property ConnectionProp(ByVal ConnectionString As String)

   Set(ByVal Value)

       m_ConnectionString = ConnectionString

   End Set

End Property

When calling it in the Initialization section of the class I get the following error: "'Argument not specified for parameter 'ConnectionString' of 'Public WriteOnly Property DefaultConnectionString(ConnectionString As String) As Object'"

EricJ

 
Old July 1st, 2005, 08:57 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Is there a particular reason you are trying to use a Module? You can do what you are looking to do with a class that has shared members. It will serve the same purpose and probably cause you less headaches.

The property problem is that your signature is incorrect. It should look like this:

    Public WriteOnly Property ConnectionProp() As String
        Set(ByVal Value As String)
            m_ConnectionString = ConnectionString
        End Set
    End Property


-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
Using modules drmacy BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 September 21st, 2007 10:39 AM
public article - public articledetails _keysersoze_ BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 September 8th, 2007 08:38 AM
Passing Public Variables in Code-Behind striker9 ASP.NET 2.0 Basics 7 February 11th, 2006 03:54 PM
Class modules lallemantdo Excel VBA 4 August 24th, 2005 08:35 PM
Class Modules ezzedin Beginning VB 6 2 June 9th, 2003 03:04 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.