Marking a class as invalid 
Author Message
 Marking a class as invalid

I am trying to script which contains a class. In
the class I am using a Class_Initialize event
handler to
perform some initial actions. There are some cases
where these actions could fail. I would like to be

able to mark the class as invalid so that when I
perform:

set objClass = new Myclass

the objClass variable wout be set to Nothing. That
way I can either explicitly test the variable with
IsObject.

My first thought was to use the statement:

Set Me = Nothing

when the error occurs, but this produces a
compilation error.

One thing that I was able to do was define a
public variable in the class that I use an an
error flag. The
first thing I do when I enter the  Class is set
the variable to 0 and then if an error occurs
during
inititialization I set the variable to 1. Then,
once I instantiate the class I check the variable
and if it is
not zero I know that an error occurred. But this
seems clunky.

Any suggestions?



Mon, 18 Oct 2004 00:32:14 GMT  
 Marking a class as invalid

Quote:
> I am trying to script which contains a class. In
> the class I am using a Class_Initialize event
> handler to
> perform some initial actions. There are some cases
> where these actions could fail. I would like to be

> able to mark the class as invalid so that when I
> perform:

simply raise an error...

Err.Raise 9999,"classname initialize","oops...a boo-boo happened!"

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--



Mon, 18 Oct 2004 05:22:47 GMT  
 Marking a class as invalid
You can't do anything with a class without it being instantiated at some
point - and thus running the class_initialise sub.

In order to mark a class as being invalid, you could drop the
class_initialise altogether in favour of a specific method to call that
would tell you if the class was OK to use in later scripts. On the other
hand, use the class_initialise to set a property in the class to be true or
false and check that after instantiation to see if it's OK to go ahead and
use it.

Only suggestions really.

Chris Barber.



I am trying to script which contains a class. In
the class I am using a Class_Initialize event
handler to
perform some initial actions. There are some cases
where these actions could fail. I would like to be

able to mark the class as invalid so that when I
perform:

set objClass = new Myclass

the objClass variable wout be set to Nothing. That
way I can either explicitly test the variable with
IsObject.

My first thought was to use the statement:

Set Me = Nothing

when the error occurs, but this produces a
compilation error.

One thing that I was able to do was define a
public variable in the class that I use an an
error flag. The
first thing I do when I enter the  Class is set
the variable to 0 and then if an error occurs
during
inititialization I set the variable to 1. Then,
once I instantiate the class I check the variable
and if it is
not zero I know that an error occurred. But this
seems clunky.

Any suggestions?



Mon, 18 Oct 2004 05:56:15 GMT  
 Marking a class as invalid

Quote:

> > I am trying to script which contains a class. In
> > the class I am using a Class_Initialize event
> > handler to
> > perform some initial actions. There are some cases
> > where these actions could fail. I would like to be

> > able to mark the class as invalid so that when I
> > perform:

> simply raise an error...

> Err.Raise 9999,"classname initialize","oops...a boo-boo happened!"

I finally did come across that. It seems to work for my purposes. I
guess I am too accustomed to the C++ way of doing things.


Mon, 18 Oct 2004 06:22:18 GMT  
 Marking a class as invalid

Quote:

> You can't do anything with a class without it being instantiated at some
> point - and thus running the class_initialise sub.

> In order to mark a class as being invalid, you could drop the
> class_initialise altogether in favour of a specific method to call that
> would tell you if the class was OK to use in later scripts. On the other
> hand, use the class_initialise to set a property in the class to be true or
> false and check that after instantiation to see if it's OK to go ahead and
> use it.

> Only suggestions really.

I did try that. It seemed clunky to me - although it did function correctly. I
like the other guy's suggestion of raising an error better. At least it fits
into the general scheme of how VBScript works.


Mon, 18 Oct 2004 06:23:27 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. CDONTS.NewMail error -- Invalid class string

2. HELP!!! VBScript Error message: Invalid class

3. VBScript Error message: Invalid class

4. Invalid Class String on CreateObject

5. CDO & Invalid Class String

6. CDONTS.NewMail error -- Invalid class string

7. Error 13 Invalid Type in class module

8. Invalid Class String .

9. oleisapi.dll 'Invalid Class String' message

10. Invalid Class String

11. Run-Time Error 2247: Invalid use of dot operator or invalid parentheses

 

 
Powered by phpBB® Forum Software