Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Global variables and object constructors

Status
Not open for further replies.

venkman

Programmer
Oct 9, 2001
467
US
I'm trying to make an array global within a project, so that different modules can use it. I was thinking the best way to do this would be to create a class which contains the array as a private variable which can be accessed through the property set and get methods. I no how I would do this in c++, but I'm new to vb/vba and I'm not sure how to do this. I'd like the array to be automatically initialized to some values when the object is constructed. So far I'm having two problems:
1. I can't figure out how to build a constructor. I tried:

Private Sub myClass_Initialize()
msgbox "constructor called"
End Sub

... and nothing happened when I called this code in another module:

Dim myobj as myClass
Set myobj = New myClass
myobj.someMethod

where someMethod does nothing


2. Can't get Static Variables to work. I wrote these two methods:

Public Sub showint()
MsgBox myint
End Sub

Public Sub yo()
Static myint As Integer
myint = 15
End Sub

And called them in a procedure in another module like this:

myobj.yo
myObj.showint

The result was that a blank dialog box, not showing myint, was displayed.

So what am I missing? btw, I'm using vba with Outlook 2000.

-Venkman
 
solved constructor problem (guess it's "Class_Initialize()" no matter what the name of the class is). Still having trouble with static variables.

-venkman
 
and solved the other problem by declaring the variable using dim outside all method declarations and setting it in the constructor. Dang, tek-tips, you guys were slow today!
-Venkman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top