msvisual.com Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Global Object Creation

 
Post new topic   Reply to topic    msvisual.com Forum Index -> VB Enterprise
Author Message
busboy10



Joined: 28 Jan 2008
Posts: 3

PostPosted: Mon Jan 28, 2008 7:24 pm    Post subject: Global Object Creation Reply with quote

Hi All,

I have created a activex dll in vb6. It is a very simple dll with
some functions that do operations on an array of data. What I would
like to have happen is for different modules to be able to access this
dll object and for the array of data to stay static.

For example

public tempy as new DLLobj

mod1()
tempy.array = 1

mod2()
print tempy.array 'it would display a 1


What I am finding is that if i declare the public within the global
section of mod 1 then it works only in mod1 and not 2. I am also
finding that the data is not staying static from run to run.

In other words I want my dll to keep static data for the life of a
project and be accessible from all forms/modules/etc.

Any suggestions?

Archived from group: microsoft>public>vb>enterprise
Back to top
View user's profile Send private message
Ken Halter



Joined: 04 Oct 2007
Posts: 4150

PostPosted: Mon Jan 28, 2008 8:03 pm    Post subject: Re: Global Object Creation Reply with quote

"busboy10" wrote in message @e6g2000prf.googlegroups.com...
> Hi All,
>
> I have created a activex dll in vb6. It is a very simple dll with
> some functions that do operations on an array of data. What I would
> like to have happen is for different modules to be able to access this
> dll object and for the array of data to stay static.
>
> For example

Where is this line of code? To make it work the way you want, it will need
to be in a standard BAS module.

....and, imo, "As New" should die I like taking control of when/where my
objects are created and destroyed.

First (and most important of all), make sure you have Option Explicit at the
top of *every* module. Otherwise, you're probably assigning values to thin
air.

> public tempy as new DLLobj

If you start a new project, add a BAS module, a Class module, an additional
form and paste this code in the appropriate places, you'll see "global"
access to an object is pretty straight forward.

'===========Standard BAS module (Module1) code
'Of course, you'll have to set the Startup Object = Sub Main to get this
'to work.....
Option Explicit

Public SomeObject As Class1

Public Sub Main()
'instantiate the class
Set SomeObject = New Class1

'show the forms (form1 will be on top of form2)
Form2.Show
Form1.Show

End Sub
'===========Form1 code. Does nothing but set a value when you click a button
Option Explicit

Private Sub Command1_Click()
SomeObject.SomeValue = 1
End Sub
'===========Form2 code. Does nothing but report a value when you click a
button
Option Explicit

Private Sub Command1_Click()
MsgBox SomeObject.SomeValue
End Sub
'===========Class1 code. Does nothing but store a value
Option Explicit

Public SomeValue As Long
'===========


--
Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
In Loving Memory - http://www.vbsight.com/Remembrance.htm

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    msvisual.com Forum Index -> VB Enterprise All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group