Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



Reply
Create New Object Like in JS?
Old 08-25-2005, 11:14 AM Create New Object Like in JS?
funkdaddu's Avatar
Web Design Snob

Posts: 635
Trades: 0
How can I create my own objects in ASP, like I would in Javascript:
Code:
var myObj = new Object();
Thanks.
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
 
Register now for full access!
Old 08-25-2005, 11:35 AM
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Code:
set var_name = server.createobject("Object")
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 08-25-2005, 11:44 AM
funkdaddu's Avatar
Web Design Snob

Posts: 635
Trades: 0
Code:
Server object error 'ASP 0177 : 800401f3'

Server.CreateObject Failed

/asp/test.asp, line 2

Invalid ProgID. For additional information specific to this message please visit the Microsoft Online Support site located at: http://www.microsoft.com/contentredirect.asp.

I guess my host doesn't support that. Oh well. Thanks.
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 08-25-2005, 11:52 AM
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Invalid ProgID means you tried to create an object that isn't registered

What was the code
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 08-26-2005, 04:26 PM
funkdaddu's Avatar
Web Design Snob

Posts: 635
Trades: 0
Just what you had: set var_name = server.createobject("Object")
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 08-26-2005, 05:05 PM
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Right!

("Object") is simply a placeholder for the parent object you are creating, Simply used here to indicate the syntax. So creating a ADO Database Connection is
Code:
Set objConn = Server.CreateObject("ADODB.Connection")
It also depends on which language you are using for ASP. With JScript the syntax is the same as javascript and as the ASP language can be VbScript you also have the similar syntax there for instantiating objects.
Creating a regular expression for example is
Code:
Set objRegEx = New RegExp
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 08-30-2005, 12:05 PM
funkdaddu's Avatar
Web Design Snob

Posts: 635
Trades: 0
Ah, see, I'm thinking of creating my own object like you can in JavaScript, here's the JS code:

HTML Code:
function run() {
	var myObj = new Object();
	
	myObj.name = "John";
	myObj.age = 21;
	myObj.add = function(x,y) { return x+y };
	myObj.print = function() { document.getElementById("output").innerText = myObj.name + " is " + myObj.age + " years old"};
}
So if I call myObj.print(); it prints "John is 21 years old" and if I call myObj.add(5,3) I get 8... I didn't know if in ASP you could create your own objects on the fly.

I've never used Jscript inside ASP, does that mean I can write in JS and have the server render it instead of the client?

Edit: Wow, for some reason I though JScript ASP was something else... very interesting.

This works:
HTML Code:
<% @Language = JScript %>
<%
var myObj = new Object();
        
myObj.name = "John";
myObj.age = 21;
myObj.add = function(x,y) { return x+y };
myObj.print = function() { return myObj.name + " is " + myObj.age + " years old"};

Response.Write(myObj.print());
%>
But does VBScript support user-created objects?

Last edited by funkdaddu; 08-30-2005 at 12:46 PM..
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 08-30-2005, 12:53 PM
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Right, With you now!

Not in ASP as such
To clarify, ASP is NOT a language it is a interpreter system and has two languages that you can use. VBScript and JScript.
ASP with JScript is MS's version of JSP and has the javascript/Java syntax. VBScript (Visual Basic Scripting) is a limited version of VB.
What you are looking for is called classes in VBscript. Basically it is OOP but this is MS territory and of course following suit is not their strong point.

This article from 4Guys Using Classes within VBScript is excellent and covers the subject very well.

And yes, to use JScript with ASP pages is very much like using javascript rendered at the server. There are a few differences to be aware of between client side and server-side obviously.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 08-30-2005, 01:27 PM
funkdaddu's Avatar
Web Design Snob

Posts: 635
Trades: 0
Got it, that makes it clearer. Thanks.
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Reply     « Reply to Create New Object Like in JS?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.23355 seconds with 12 queries