Solved

passing an argument into the class initialisation function

Posted on 2003-11-20
5
174 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

726 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