Solved

passing an argument into the class initialisation function

Posted on 2003-11-20
5
168 Views
Last Modified: 2010-05-03
I have create a class module ("style")

in the class I have used the initialise function, I want this function to accept a 'string' as an argument.

ie private sub initialize(textBlock as string)



However when I try to create this class, I do not know how to pass the string to the class, I would have thought it would be as follows:

dim tS as style
set tS = new style(myString)

However this produces an error.

Could someone please enlighten me as to how this works.

Thanks,
Cassandra


0
Comment
Question by:calebS
  • 2
5 Comments
 
LVL 9

Accepted Solution

by:
dancebert earned 45 total points
ID: 9790593
Which version of VB?  You can't do this in VB6 or earlier.
0
 
LVL 1

Author Comment

by:calebS
ID: 9790865
Yes, it is VB6.

So is there anyway I can get around this?

The only way I can think of would be to create a public 'onInitialise' class:
ie public function onInitialise(textBlock)



then to create the class I could do the following:

dim tS as style
set tS = new style
tS.onInitialise(textBlock)

It would of course leave room for error (I could forget to call the onInitialise class), it wouldn't be too hard to put a switch in it so that it could only ever be called once.

Is this my only option?





0
 
LVL 7

Assisted Solution

by:Z_Beeblebrox
Z_Beeblebrox earned 45 total points
ID: 9790930
Unfortunately, yes, that is your only option. You probably want to put a check in all of your other functions to make sure that your onInitialize function has been called and throw an error if it hasn't to minimize the chance of errors.

Or, you could switch to VB.Net.... :)

Zaphod.
0
 
LVL 1

Author Comment

by:calebS
ID: 9790949
I thought about switching, but this little project is on a tight time frame, and I want to switch to C# when I do. So I will finish it first, then spend a month or two making the change.

thanks for your help
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now