Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Basics
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 7th, 2004, 09:49 PM
Registered User
Join Date: Jan 2004
Location: Brisbane, QLD, Australia.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Instantiating a VBScript class in JavaScript

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.

Reply With Quote
  #2 (permalink)  
Old January 8th, 2004, 08:22 AM
Friend of Wrox
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post

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
' 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
var x = callBarMethod(param1, param2, paramN);
Reply With Quote
  #3 (permalink)  
Old January 8th, 2004, 08:22 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

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.

Work smarter, not harder.
Reply With Quote
  #4 (permalink)  
Old January 12th, 2004, 11:17 AM
Friend of Wrox
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post

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
Reply With Quote
  #5 (permalink)  
Old July 14th, 2004, 11:47 AM
Registered User
Join Date: Jul 2004
Location: Louisville, CO, .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

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.

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 03:17 PM.

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