Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 7th, 2004, 09:49 PM
Registered User
 
Join Date: Jan 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Instantiating a VBScript class in JavaScript

Hi
I have created a class in VBScript (server-side) and would like to instantiate it from within JavaScript (server-side). At the top of my ASP page (the one containing the server-side JavaScript) I have used an #include statement to reference the page with the VBScript. Is it at all possible to instantiate a VBScript class in JavaScript? I have scoured the web for the last couple of hours and have not been able to get an answer. Much appreciated of any help.

Cheers
Russell
 
Old January 8th, 2004, 08:22 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

I had a similar problem where I wanted to instantiate a js class from vbs and I never found a way to do it directly. What I did instead was write wrapper functions in js for each of the class methods I wanted to call - luckily I only had a few methods.

For example lets say you have a VB class called foo with a single method called bar. Then what you do is
1.add a new VBS variable to contain the class instance
2.add a new wrapper function to create the class object and store it in the new variable
3.add a new wrapper function to call the class method using the new stored variable
example:
Code:
' VBS code
Dim vbClassVar
Function createFooClass()
    Set vbClassVar = New foo
End Function
Function callBarMethod(param1, param2, paramN)
    callBarMethod = vbClassVar.bar(param1, param2, paramN)
End Function

//JS code
createFooClass(); 
var x = callBarMethod(param1, param2, paramN);
hth
Phil
 
Old January 8th, 2004, 08:22 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I think you are out of luck with this. They are two different languages. I know that with the right pokes and prods you can get client-side VBS and JS to share variables, but not much more than that. But server-side, I can't imagine it'd be possible.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old January 12th, 2004, 11:17 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Another way to do this would be to turn your VBS class into a scriptlet, which is a COM object written in script. You would then be able to create the VBS class from JS using the standard COM way of new ActiveXObject(...)

see here for more details on scriptlets
http://msdn.microsoft.com/library/de...letcreates.asp
 
Old July 14th, 2004, 11:47 AM
Registered User
 
Join Date: Jul 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

There is actually a really easy way to do this. Assume an object "Foo." In your VB class file, but not the class itself, create a "constructor" function that looks like this:

Function NewFoo()
   Set NewFoo = New Foo
End Function

Class Foo
    [Foo code here]
End Class


In the javascript code, you'd do this:

var oFoo = NewFoo()

You can optionally pass in arguments to this function (if the VB corresponding function accepts them) and configure your new object appropriately.

&y





Similar Threads
Thread Thread Starter Forum Replies Last Post
JavaScript to VBScript Thomas82 Classic ASP Basics 1 July 29th, 2006 07:03 PM
Javascript and VBScript woes 1up Javascript How-To 18 November 7th, 2005 03:18 PM
Using VBScript variables in Javascript PL Classic ASP Basics 4 July 29th, 2004 03:05 PM
vbscript and javascript together erin VBScript 1 October 21st, 2003 02:48 PM
Using VBScript and JavaScript together jwalborn Classic ASP Professional 2 October 13th, 2003 10:06 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.