Page 1 of 2 12>
Topic Options
#92528 - 2003-07-24 03:00 PM IDispatch pointers.... Error
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 Offline
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 ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#92530 - 2003-07-24 03:10 PM Re: IDispatch pointers.... Error
Howard Bullock Offline
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.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#92531 - 2003-07-24 03:18 PM Re: IDispatch pointers.... Error
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 Offline
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 ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#92533 - 2003-07-24 03:57 PM Re: IDispatch pointers.... Error
Howard Bullock Offline
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?
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#92534 - 2003-07-24 04:12 PM Re: IDispatch pointers.... Error
Howard Bullock Offline
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 ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#92535 - 2003-07-24 05:02 PM Re: IDispatch pointers.... Error
Chris S. Offline
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
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 Offline
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 ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#92538 - 2003-07-24 06:15 PM Re: IDispatch pointers.... Error
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
I'm pretty sure you can't do that because Ruud disabled this assignment of "default" values I believe. However, without seeing the whole script or what type of object is used, I can't really comment.
_________________________
There are two types of vessels, submarines and targets.

Top
#92539 - 2003-07-24 06:26 PM Re: IDispatch pointers.... Error
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 Offline
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.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#92541 - 2003-07-24 07:23 PM Re: IDispatch pointers.... Error
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
#92542 - 2003-07-24 07:42 PM Re: IDispatch pointers.... Error
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
As I already mentioned, it would help if you'd post the complete script. There might be other things to consider.

[ 24. July 2003, 20:04: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#92543 - 2003-07-24 07:57 PM Re: IDispatch pointers.... Error
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
#92544 - 2003-07-24 08:04 PM Re: IDispatch pointers.... Error
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
That's what I've been looking for
code:
;Object Creation
$objFSO = CreateObject("Scripting.FileSystemObject")
$objSoftware = CreateObject("ADODB.RecordSET")
$rs_Legacy = CreateObject("ADODB.RecordSET")
$rs_HotFixes = CreateObject("ADODB.RecordSET")

You might wan to take a look at the UDF Forum under DBCommand() - Executes a SQL statement and returns a recordset if applicable and the other database UDfs that have been placed there.

[ 24. July 2003, 20:04: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#92545 - 2003-07-24 08:18 PM Re: IDispatch pointers.... Error
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
#92546 - 2003-07-24 08:25 PM Re: IDispatch pointers.... Error
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Hmm, don't think you can use DBCommand() with a virtual recordset, it's designed to work with databases like Ms Access, SQL Server, MySQL.

However, you should be able to use at least DBGetRecordset() and DBExecuteSQL() as they require an open recordset to be present.

[ 24. July 2003, 20:26: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#92547 - 2003-07-24 10:14 PM Re: IDispatch pointers.... Error
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Jase, what took you so long to post over here anyway? [Wink]

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
Page 1 of 2 12>


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1003 anonymous users online.
Newest Members
StuTheCoder, M_Moore, BeeEm, min_seow, Audio
17884 Registered Users

Generated in 0.068 seconds in which 0.024 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org