Author |
Message |
Paul Meye #1 / 10
|
 Passing Arrays between ASP/VBScript and ActiveX Components...
Hello... Can anyone help. I have seen this question asked a few times around the joint, but I've never seen a good answer to it. (good == one that works for me :>) Can anyone supply some sample code on how to pass an array from an ActiveX component to ASP code (VBScript) I keep getting an error: Type Mismatch (undefined) Thanks in advance Paul Meyer Perth College IT Department
|
Sun, 31 Dec 2000 03:00:00 GMT |
|
 |
Aaron Bertran #2 / 10
|
 Passing Arrays between ASP/VBScript and ActiveX Components...
Quote: > Can anyone supply some sample code on how to pass an array from an ActiveX >component to ASP code (VBScript)
By ActiveX component, do you mean client-side or server-side component (e.g. an OCX in the browser, or a DLL on the server)? Quote: >I keep getting an error: Type Mismatch (undefined)
Let's see the code you've started with... ____________________ Aaron Bertrand Senior Developer W a t e r w o r k s I n t e r a c t i v e , I n c o r p o r a t e d 360 Thames Street Newport, RI 02840 401.848.0342 x18
|
Sun, 31 Dec 2000 03:00:00 GMT |
|
 |
Paul Meye #3 / 10
|
 Passing Arrays between ASP/VBScript and ActiveX Components...
I'm using an ActiveX Server DLL. Heres a snippet of some test code: --------8<---------- snip ----------8<---------- '(VB Function) Public Function szArray() As Variant Dim aTmp(5) as Integer for i=0 to 4 aTmp(i) = "Position " & i next szArray = aTmp End Function '(ASP Page) <% Dim aTest Server.CreateObject("Test.ra") aTest = szArray() response.write ubound(aTest) %> --------8<---------- snip ----------8<---------- TIA... Paul Quote:
>> Can anyone supply some sample code on how to pass an array from an >ActiveX >>component to ASP code (VBScript) >By ActiveX component, do you mean client-side or server-side component (e.g. >an OCX in the browser, or a DLL on the server)? >>I keep getting an error: Type Mismatch (undefined) >Let's see the code you've started with... > ____________________ > Aaron Bertrand > Senior Developer > W a t e r w o r k s > I n t e r a c t i v e , > I n c o r p o r a t e d > 360 Thames Street > Newport, RI 02840 > 401.848.0342 x18
|
Mon, 01 Jan 2001 03:00:00 GMT |
|
 |
Aaron Bertran #4 / 10
|
 Passing Arrays between ASP/VBScript and ActiveX Components...
Quote: > aTest = szArray()
You have to retrieve it from the DLL (here you are trying to access the LOCAL array szArray, which doesn't exist (you probably get undefined for the ubound, right?). <% ' FIRST YOU CREATE THE OBJECT: set a = server.createObject("project.class") ' THEN YOU MUST CALL A METHOD TO ' RETURN A VALUE OR RUN A FUNCTION: a.szArray() ' THEN YOU CALL THE ARRAY LOCALLY: aTest = a.szArray response.write(ubound(aTest)) %> There is also a way you can do a response.write from inside the DLL, if transferring the array causes problems... ____________________ Aaron Bertrand Senior Developer W a t e r w o r k s I n t e r a c t i v e , I n c o r p o r a t e d 360 Thames Street Newport, RI 02840 401.848.0342 x18
|
Mon, 01 Jan 2001 03:00:00 GMT |
|
 |
John Kesle #5 / 10
|
 Passing Arrays between ASP/VBScript and ActiveX Components...
>There is also a way you can do a response.write from inside the DLL, And how do you do that Aaron? john k Quote:
>> aTest = szArray() >You have to retrieve it from the DLL (here you are trying to access the >LOCAL array szArray, which doesn't exist (you probably get undefined for the >ubound, right?). ><% >' FIRST YOU CREATE THE OBJECT: >set a = server.createObject("project.class") >' THEN YOU MUST CALL A METHOD TO >' RETURN A VALUE OR RUN A FUNCTION: >a.szArray() >' THEN YOU CALL THE ARRAY LOCALLY: >aTest = a.szArray >response.write(ubound(aTest)) >%> >There is also a way you can do a response.write from inside the DLL, if >transferring the array causes problems... > ____________________ > Aaron Bertrand > Senior Developer > W a t e r w o r k s > I n t e r a c t i v e , > I n c o r p o r a t e d > 360 Thames Street > Newport, RI 02840 > 401.848.0342 x18
|
Mon, 01 Jan 2001 03:00:00 GMT |
|
 |
Aaron Bertran #6 / 10
|
 Passing Arrays between ASP/VBScript and ActiveX Components...
Well, this is how I bring home the bacon, so I can't tell you everything. :) Just kidding... Assuming you use VB5 to make your DLL, you have to add "Microsoft Active Server Pages Object Library" under Project|References. Here's the VB code: <SNIP> Option Explicit Private myResponse As IResponse Public Function OnStartPage(aspScriptingContext As ScriptingContext) On Error Resume Next Set myResponse = aspScriptingContext.Response End Function Public Function someCall() As Long myResponse.write("Hello from the DLL") End Function </SNIP> Then you would just call it like this from ASP: <% set a = server.createobject("myCoolDLL.myCoolClass") a.someCall() set a = nothing %> ____________________ Aaron Bertrand Senior Developer W a t e r w o r k s I n t e r a c t i v e , I n c o r p o r a t e d 360 Thames Street Newport, RI 02840 401.848.0342 x18 Quote:
> >There is also a way you can do a response.write from inside the DLL, >And how do you do that Aaron?
|
Mon, 01 Jan 2001 03:00:00 GMT |
|
 |
Phil Chetcut #7 / 10
|
 Passing Arrays between ASP/VBScript and ActiveX Components...
Aaron, you are just too Cool :) -- Regards, Phil Chetcuti Visit my site for ASP sites and samples http://www.netcom.ca/~kbwcs
Quote: >Well, this is how I bring home the bacon, so I can't tell you everything. >:) Just kidding... >Assuming you use VB5 to make your DLL, you have to add "Microsoft Active >Server Pages Object Library" under Project|References. Here's the VB code: ><SNIP> >Option Explicit >Private myResponse As IResponse >Public Function OnStartPage(aspScriptingContext As ScriptingContext) > On Error Resume Next > Set myResponse = aspScriptingContext.Response >End Function >Public Function someCall() As Long > myResponse.write("Hello from the DLL") >End Function ></SNIP> >Then you would just call it like this from ASP: ><% >set a = server.createobject("myCoolDLL.myCoolClass") >a.someCall() >set a = nothing >%> > ____________________ > Aaron Bertrand > Senior Developer > W a t e r w o r k s > I n t e r a c t i v e , > I n c o r p o r a t e d > 360 Thames Street > Newport, RI 02840 > 401.848.0342 x18
>> >There is also a way you can do a response.write from inside the DLL, >>And how do you do that Aaron?
|
Tue, 02 Jan 2001 03:00:00 GMT |
|
 |
John Kesle #8 / 10
|
 Passing Arrays between ASP/VBScript and ActiveX Components...
<Bowing and chanting, "I'm not worthy, I'm not worthy..."> Nice tip Aaron. I owe you a strip of bacon. :-) john k Quote:
>Well, this is how I bring home the bacon, so I can't tell you everything. >:) Just kidding... >Assuming you use VB5 to make your DLL, you have to add "Microsoft Active >Server Pages Object Library" under Project|References. Here's the VB code: ><SNIP> >Option Explicit >Private myResponse As IResponse >Public Function OnStartPage(aspScriptingContext As ScriptingContext) > On Error Resume Next > Set myResponse = aspScriptingContext.Response >End Function >Public Function someCall() As Long > myResponse.write("Hello from the DLL") >End Function ></SNIP> >Then you would just call it like this from ASP: ><% >set a = server.createobject("myCoolDLL.myCoolClass") >a.someCall() >set a = nothing >%> > ____________________ > Aaron Bertrand > Senior Developer > W a t e r w o r k s > I n t e r a c t i v e , > I n c o r p o r a t e d > 360 Thames Street > Newport, RI 02840 > 401.848.0342 x18
>> >There is also a way you can do a response.write from inside the DLL, >>And how do you do that Aaron?
|
Tue, 02 Jan 2001 03:00:00 GMT |
|
 |
Paul Meye #9 / 10
|
 Passing Arrays between ASP/VBScript and ActiveX Components...
Aaron... I've tried this, but it still did not work, I got a different type mismatch. How am I to define the function in the VB project? Do I declare the array as a variant in the VB function? or as a normal array? and the function should return a variant? Heres that code again jic... --------8<---------- snip ----------8<---------- '(VB Function) Public Function szArray() As Variant Dim aTmp(5) as Integer for i=0 to 4 aTmp(i) = "Position " & i next szArray = aTmp End Function '(ASP Page) <% Dim aTest Dim oTest set oTest = Server.CreateObject("Test.ra") aTest = oTest.szArray() response.write ubound(aTest) %> --------8<---------- snip ----------8<---------- I'm beginning to feel more and more like a newbie! :) Can anyone recommend any good books to brush up my skills especially in the VB ActiveX side of things. Thanks in advance... You've been a great help so far. BFN... Paul Quote:
>> aTest = szArray() >You have to retrieve it from the DLL (here you are trying to access the >LOCAL array szArray, which doesn't exist (you probably get undefined for the >ubound, right?).
|
Fri, 05 Jan 2001 03:00:00 GMT |
|
 |
Phil Jerkin #10 / 10
|
 Passing Arrays between ASP/VBScript and ActiveX Components...
Paul: Your VB function definition looks great. However, your array is an array of integers. VBScript (in which your ASP code is written) can only use variants. So, your aTmp array should be dimensioned like this: Dim aTmp(5) As Variant Other than that, your code looks fine. Hope this helped! Phil Jerkins Netrify Technologies, Inc.
Quote: >--------8<---------- snip ----------8<---------- >'(VB Function) >Public Function szArray() As Variant > Dim aTmp(5) as Integer > for i=0 to 4 > aTmp(i) = "Position " & i > next > szArray = aTmp >End Function >'(ASP Page) ><% > Dim aTest > Dim oTest > set oTest = Server.CreateObject("Test.ra") > aTest = oTest.szArray() > response.write ubound(aTest) >%> >--------8<---------- snip ----------8<----------
|
Fri, 05 Jan 2001 03:00:00 GMT |
|
|