Wrox Programmer Forums
BOOK: Visual Basic 2005 Programmer's Reference
This is the forum to discuss the Wrox book Visual Basic 2005 Programmer's Reference by Rod Stephens; ISBN: 9780764571985
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Visual Basic 2005 Programmer's Reference 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 January 28th, 2007, 07:44 AM
Authorized User
Join Date: Dec 2006
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default Modules and class libraries

In order to get round VB 2005's inability to share source files, I have split my applications into a shared component (in a class library) and and 3 projects that will be compiled into three separate applications and which reference the class library.

All three applications use a module that contains a set of public variables, and rather than copy this module into each application, I'd like to share it as well.

So, I put it into the class library, but even with a Public statement on the module and its variables and subroutines, I can't reference it from the main app. IMPORT shows the classes in the class library (which include a couple of forms) but not the module.

If I convert the module to a class, I'll have to change every reference to each one of its variables from "variable" to "instance.variable", and the same for its methods. Is this the only way to do it?

If you have trouble working out what I'm trying to do...
  The first app gets data from the user and saves it on disk
  The second app reads the data in and does something
  The third app reads the data in and does something else
Each needs access to the methods and class structures that store and manage the internal representation of the data.

Old January 28th, 2007, 09:54 AM
Rod Stephens's Avatar
Wrox Author
Join Date: Jan 2006
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts

Sorry but Visual Basic only allows class libraries to expose objects like this. I.e. no plain old variables. (It's one of the big problems with building "traditional" DLLs in VB. In a traditional DLL, you can do this but not in VB.)

I think you can make the variables Shared in the class and then you don't need to make a class instance to use them. If you call the class TheValues, it would look something like this:

    Public Class TheValues
        Shared Value1 As Integer
    End Class.

Then you can access them as in:

    TheValues.Value1 = 1337

Alternatively you might look into XML serialization. That would let you easily save and restore instances of the class in files and might make it easier for the three programs to read and write the same file. These two examples use serialization:


Email me if you get stuck on any of it and I can probably help.

Author of "Visual Basic 2005 Programmer's Reference"

Sign up for the free VB Helper Newsletters at http://www.vb-helper.com/newsletter.html
Old January 30th, 2007, 05:48 AM
Authorized User
Join Date: Dec 2006
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts

I've found a way of sharing source files (see IDE topic) so I've abandoned this.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Class Libraries SamsDaddy BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 4 April 18th, 2006 10:36 AM
how to pass values between class modules ? yvon Beginning VB 6 1 December 7th, 2005 05:13 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.