Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBScript passing value by reference (VarPtr) to ActiveX function

I'm trying this:

  Dim oApp
  Dim iReturnedResult

  Set oApp = CreateObject("Some.Application")
  Set F_Ord = oApp.Documents.Open("Window 1", VarPtr(iReturnedResult))

The ActiveX control expects the second parameter to be a Long by reference.

This works perfectly well inside Excel VBA. I can run this step by step, and see the result is returned like it should.

But, when I move this code to a VBS file and run it from the command line (CScript.exe), I get an error 800A000D, meaning it's the wrong type.

I have also tried creating an array instead, and tested with these commands, without any luck:

Set F_Ord = oApp.Documents.Open("Window 1", VarPtr(iReturnedResult(0)))
Set F_Ord = oApp.Documents.Open("Window 1", iReturnedResult(0))

Does anyone know how to pass a long variable by reference to an ActiveX control from VBScript?

like image 348
Øyvind Hansen Avatar asked Sep 23 '26 06:09

Øyvind Hansen


1 Answers

The simple answer is VarPtr() is not supported by VBScript.

To my knowledge, there is no equivalent that allows you to pass a pointer to a variables memory address.


Useful Links

  • Visual Basic for Applications Features Not In VBScript
like image 176
user692942 Avatar answered Sep 25 '26 14:09

user692942



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!