Solved

passing an argument into the class initialisation function

Posted on 2003-11-20
5
170 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB6 code to programmatically convert pdf to excel 21 92
JSON Response and request in VB6 application 11 424
Copy a row 12 62
Access Object Property from VBA Module in Excel 2010 2 31
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

777 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