• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 179
  • Last Modified:

passing an argument into the class initialisation function

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
calebS
Asked:
calebS
  • 2
2 Solutions
 
dancebertCommented:
Which version of VB?  You can't do this in VB6 or earlier.
0
 
calebSAuthor Commented:
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
 
Z_BeeblebroxCommented:
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
 
calebSAuthor Commented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now