#92528 - 2003-07-24 03:00 PM
IDispatch pointers.... Error
|
Anonymous
Anonymous
Unregistered
|
I have a script which creates a WMI object, queries a specific class and then dumps the information into a database. Each time I go to add a new record to the recordset, it errors out with:
IDispatch pointers not allowed in expressions!
The second line of code is what triggers the error:
$RetVal = $rs_Software.AddNew("IDN", $objInv.IdentifyingNumber) $rs_Software("Name") = $objInvt.Name
Any suggestions? - Thanks
|
|
Top
|
|
|
|
#92529 - 2003-07-24 03:05 PM
Re: IDispatch pointers.... Error
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
$rs_Software is an IDispatch pointer. You can not use it in a variable assignment like:
$rs_Software("Name") = $objInvt.Name
Maybe a little morte code would shed some light on other approaches. [ 24. July 2003, 15:06: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#92530 - 2003-07-24 03:10 PM
Re: IDispatch pointers.... Error
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Sometimes depending on the version of KiXtart, the error actually occurs on the previous line. In which case you might try removing the "$RetVal = " and check @error.
|
|
Top
|
|
|
|
#92531 - 2003-07-24 03:18 PM
Re: IDispatch pointers.... Error
|
Anonymous
Anonymous
Unregistered
|
I'm using Version 4.21. I've checked for an error after the first line, and it always returns 0. If $rs_Software is the IDispatch pointer, then what is the correct syntax within Kix to assign a property to a recordset field? This script is an adaptation from VB/VBS (where it works just fine) and the ADO syntax within the script follows the documented syntax Microsoft posts for adding new records.
|
|
Top
|
|
|
|
#92532 - 2003-07-24 03:53 PM
Re: IDispatch pointers.... Error
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Jens, Chris; a little help here...never did this before. [ 24. July 2003, 15:55: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#92533 - 2003-07-24 03:57 PM
Re: IDispatch pointers.... Error
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
To better isolate the issue, try this:
$value = $objInvt.Name ? "@error @serror" $rs_Software("Name") = $value ? "@error @serror"
What if anything fails?
|
|
Top
|
|
|
|
#92534 - 2003-07-24 04:12 PM
Re: IDispatch pointers.... Error
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Another shot in the dark:
$rs_Software.Name = $Value or $rs_Software.Name.Value = $Value [ 24. July 2003, 16:13: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#92535 - 2003-07-24 05:02 PM
Re: IDispatch pointers.... Error
|
Chris S.
MM club member
   
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
Could the problem be...
code:
$RetVal = $rs_Software.AddNew("IDN", $objInv.IdentifyingNumber)
How about...
code:
$ID = $objInv.IdentifyingNumber $RetVal = $rs_Software.AddNew("IDN", $ID)
|
|
Top
|
|
|
|
#92536 - 2003-07-24 05:32 PM
Re: IDispatch pointers.... Error
|
Anonymous
Anonymous
Unregistered
|
I appreciate everyone's help. Here is the results of each suggestion:
Code changed to:
$RetVal = $objSoftware.AddNew("IdentifyingNumber", cStr($objInvt.IdentifyingNumber)) ? "@error @serror" $varRetVal = $objInvt.Name ? "@error @serror" $objSoftware("Name") = $varRetVal ? "@error @serror"
and results were:
0 The operation completed successfully. 0 The operation completed successfully. ERROR : IDispatch........
Code changed to:
$varRetVal = cStr($objInvt.IdentifyingNumber) $RetVal = $objSoftware.AddNew("IdentifyingNumber", $varRetVal) ? "@error @serror" $varRetVal = $objInvt.Name ? "@error @serror" $objSoftware("Name") = $varRetVal ? "@error @serror"
and the results were exactly the same.
|
|
Top
|
|
|
|
#92537 - 2003-07-24 05:51 PM
Re: IDispatch pointers.... Error
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Your post indicates that the problem is with the line:
$objSoftware("Name") = $varRetVal
Have you tried my other suggestions that pertain to this line? [ 24. July 2003, 17:52: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#92539 - 2003-07-24 06:26 PM
Re: IDispatch pointers.... Error
|
Anonymous
Anonymous
Unregistered
|
Sorry about that - Missed that post all together. Those did remove the error, but did not assign the data. But your suggested syntax got me thinking about the language Kix was written in and I switched the syntax of the object command from $rs_Software("Name") = $objInvt.Name to $rs_Software!Name = $objInvt.Name and the database updated perfectly. Thanks
|
|
Top
|
|
|
|
#92540 - 2003-07-24 07:01 PM
Re: IDispatch pointers.... Error
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
I find this syntax quite interesting: $rs_Software!Name
Can you give more detail into your thought process that led you to this solution?
This looks very M$ Access basic like.
|
|
Top
|
|
|
|
#92541 - 2003-07-24 07:23 PM
Re: IDispatch pointers.... Error
|
Anonymous
Anonymous
Unregistered
|
MSDN - Their syntax for ADO on C++ uses the bang whereas VB uses the ("") syntax to identify a field. I took a guess. This is not to say that my script is functional - I wind up with a database of x entries, where all records contain the same data as the last record to be updated, but at least I am closer.
|
|
Top
|
|
|
|
#92543 - 2003-07-24 07:57 PM
Re: IDispatch pointers.... Error
|
Anonymous
Anonymous
Unregistered
|
The current script is 465 lines so I don't really want to copy it here and take up so much space. I did post it for download here (opens new window)
|
|
Top
|
|
|
|
#92545 - 2003-07-24 08:18 PM
Re: IDispatch pointers.... Error
|
Anonymous
Anonymous
Unregistered
|
Thanks - Maybe I've missed it, but is there a specific one that shows adding a new record to an open recordset? My script does not make any actual connections to a database; I use the virtual recordset only to store temporary data and perform sorts on it.
|
|
Top
|
|
|
|
#92547 - 2003-07-24 10:14 PM
Re: IDispatch pointers.... Error
|
Chris S.
MM club member
   
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
Jase, what took you so long to post over here anyway?
BTW, thanks for hosting www.dx21.com, I've been using it as a resource for years. [ 24. July 2003, 22:42: Message edited by: Chris S. ]
|
|
Top
|
|
|
|
Moderator: Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
|
0 registered
and 1003 anonymous users online.
|
|
|