#86646 - 2002-07-11 12:26 AM
Re: error when checking if object was created
|
MightyR1
MM club member
Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
|
|
Top
|
|
|
|
#86653 - 2002-07-10 03:11 PM
Re: error when checking if object was created
|
Chris S.
MM club member
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
I chose the "if not $root" checking because 1) it works (at least for now) and 2) because I use KiXGUI with my logon script and I wrote it to handle both KiXGUI output and console output if the client is unable to register KiXGUI for some reason. Therefore, I have to make checks throughout my script to verify that KiXGUI is running. My original script was based on the example in the KiXGUI.zip file which I'm finding out now is rife with things not considered 'best practice.'
I may change it in the future to something more like this...
code:
$root=createobject("KiXGUI.Desktop") if @error ? "KiXGUI not registered." else $GUIOK=1 endif
|
Top
|
|
|
|
#86655 - 2002-07-12 01:48 AM
Re: error when checking if object was created
|
Alex.H
Seasoned Scripter
Registered: 2001-04-10
Posts: 406
Loc: France
|
Last kixgui release was little after kixtart 4.02, so yes, no compliance with 4.10a
_________________________
? getobject(Kixtart.org.Signature)
|
Top
|
|
|
|
#86658 - 2002-07-13 07:56 AM
Re: error when checking if object was created
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
What if we wrap it in a UDF and bury the object check in there?
Since KiXtart 4.10 supports default properties and methods, how does one distinguish between an object with default properties or methods and one without any default properites?
The following code serves two purposes. First, it is an example of the UDF discussed above. Second, attempting to print the object yields text for the "Excel.Application" object, a zero (Boolean) for a failure to create the object, and a catastrophic script failure for the "WScript.Shell" object which apparently doesn't have default properties.
I used two if statement just to verify the 'NOT' or lack thereof did not behave differently than expected. Execute with 4.10. code:
Break on ? "Object1" $object1=udfCreateObject('Excel.Application') if $object1 ? "Object Exists" ? $Object1 endif if not $object1 ? "No Object" ? $Object1 endif
? ? "Object2" $object2=udfCreateObject('Bogus') if $object2 ? "Object Exists" ? $Object2 endif if not $object2 ? "No Object" ? $Object2 endif
? ? "Object3" $object3=udfCreateObject('WScript.Shell') if $object3 ? "Object Exists" ? $Object3 endif if not $object3 ? "No Object" ? $Object3 endif
Function udfCreateObject($A) Dim $B $B = CreateObject($A) If VarTypeName($B) = "Object" $udfCreateObject = $B Else ? "Error creating object '"'$A'"'" $udfCreateObject = NOT 1 Endif Endfunction
[ 13 July 2002, 08:01: Message edited by: Howard Bullock ]
|
Top
|
|
|
|
Moderator: Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
|
2 registered
(morganw, mole)
and 414 anonymous users online.
|
|
|