calling asp/vbscript experts?

Status
Not open for further replies.

E3

Ars Centurion
387
I read on a asp book i borrowed.
It says something on "component instantiated with app.class string Auction.AuctionData" But it doesn't state how to go about it . Can anyone explain abit ?


Another question , see line 5? whats the "Aspcom","Sa","" doing over there? has it gotta do with something i read on classes?

Public Function GetCategories()
Dim Conn As New ADODB.Connection
Dim RSCategories As ADODB.Recordset

Conn.Open "ASPComp","sa",""
Set RSCategories = Conn.Execute("Select CategoryName " _
& "from Categories Order By CategoryName")

Do Until RSCategories.EOF
GetCategories = GetCategories & "<OPTION VALUE=""" _
& RSCategories("CategoryName") _
& """>" & RSCategories("CategoryName") _ "</Option>"
RSCategories.MoveNext
 

temp

Seniorius Lurkius
44
I read on a asp book i borrowed.
It says something on "component instantiated with app.class string Auction.AuctionData" But it doesn't state how to go about it . Can anyone explain abit ?

Instantiating something in vbscript means using the CreateObject statement. You would write
code:<HR>
Code:
' Declare variable first because we are good citizens:
Dim MyAuctionObject
' Instantiate object:
Set MyAuctionObject = CreateObject("Auction.AuctionData")
The string "Auction.AuctionData" is what we call the "App class string".

The other line you were puzzling over opens a connection to a database. Specifically the author had already created a DSN or "Machine ODBC data source" called "ASPComp". "sa" is the username for the database and final argument "" is the password. Great security huh?

You set up data sources to have an easy and consistent method of connecting to some specific database. If you want to try for yourself you should try to find the "Data Sources" applet in the Windows control panel.

To make matters more confusing many ASP programmers do not use this method of connecting to a database any more, but instead specify a "Connection String". Here's a commented example fromASP 101.
 

E3

Ars Centurion
387
Now I have a problem, I typed the entire class out ,wanting to see the effects of it but

Auction.AuctionData

The class is named Auctiondata. Whats puzzling is wat file extension do i save the file as? normal .asp??

Another problem is "Auction". hmmm. isit just a dummy variable? I sort of know its a set of component as describe by the book and auctiondata is part of it (there are other classes shown in the book).
But there are not codes in the book for "Auction". So is it aright to leave it out when I try to instantiate the classes???

Or is there any particular way of organising or saving the classes that i have to accomdate "Auction".

vague, but i hope someone understands what I m trying to say and give me a helping hand. :)
 

wookiecrisp

Ars Scholae Palatinae
891
Doesn't your book tell you what extension to save the code as? You can write classes in .asp files, but usually people write the classes in VB, and then compile them into a .dll. Either way, it should work.

If you class is named 'AuctionData', then in an asp page, I believe you create an object of that class first:

dim objAuctionData
set objAuctionData = New AuctionData

Then if you wanted to access a variable or function/subroutine of your class, you would do:

objAuctionData.VariableName = value

or

value = objAuctionData.FunctionName(parameters)

Hope that at least makes things a little clearer for you.
 

E3

Ars Centurion
387
i tried using but i got this error
/auctionmenu.asp, line 4, column 19
set MyAuction = New("AuctionData")
------------------^


Not giving up, I tried another way of declaring

<%@ Language=VBScript %>
<%Option Explicit
Dim MyAuction
set MyAuction = Server.CreateObject("AuctionData.asp")
%>

and ended up getting this

Error Type:
Server object, ASP 0177 (0x800401F3)
Invalid ProgID. For additional information specific to this message please visit the Microsoft Online Support site located at: http://www.microsoft.com/contentredirect.asp.
/auctionmenu.asp, line 4


any idea whats up with it? :p
 

mauerj

Wise, Aged Ars Veteran
121
Originally posted by E3:

i tried using but i got this error
/auctionmenu.asp, line 4, column 19
set MyAuction = New("AuctionData")
------------------^

should be
Set MyAuction = New AuctionData

Not giving up, I tried another way of declaring

<%@ Language=VBScript %>
<%Option Explicit
Dim MyAuction
set MyAuction = Server.CreateObject("AuctionData.asp")
%>

and ended up getting this

Error Type:
Server object, ASP 0177 (0x800401F3)
Invalid ProgID. For additional information specific to this message please visit the Microsoft Online Support site located at: http://www.microsoft.com/contentredirect.asp.
/auctionmenu.asp, line 4

any idea whats up with it? :p

Yeah, it's wrong. Auctiondata.asp is a file, not a ProgID. You need to pass a ProgID to CreateObject (like Scripting.FileSystemObject for example).
 

E3

Ars Centurion
387
eh?

<%@ Language=VBScript %>

<%Option Explicit
Dim MyAuction
Set MyAuction = New AuctionData
%>
<Select Name = "Category">
<%
Response.Write MyAuction.GetCategories
%>
</Select>


This is the AuctionData.asp class I m attempting to use ...
<%@ Language=VBScript %>

<Script Language = VBScript>
Public Function GetCategories()
Dim Conn As New ADODB.Connection
Dim RSCategories As ADODB.Recordset

Conn.Open "fyp","abc","abc"
Set RSCategories = Conn.Execute("Select CategoryName " _
& "from Categories Order By CategoryName")

Do Until RSCategories.EOF
GetCategories = GetCategories & "<OPTION VALUE=""" _
& RSCategories("CategoryName") _
& """>" & RSCategories("CategoryName") _ "</Option>"
RSCategories.MoveNext
Loop
End Function


Error Type:
Microsoft VBScript runtime (0x800A01F4)
Variable is undefined: 'AuctionData'
/auctionmenu.asp, line 5

:( :(
 

wookiecrisp

Ars Scholae Palatinae
891
Your problem is simple...

The code thinks 'AuctionData' is a variable because you never defined it as a class in 'AuctionData.asp'. Solution, put a class around your code in 'AuctionData.asp'.

code:<HR>
Code:
<%@ Language=VBScript %><P><Script Language = VBScript><P><B>Class AuctionData</B><P>Public Function GetCategories()
Dim Conn As New ADODB.Connection
Dim RSCategories As ADODB.Recordset<P>Conn.Open "fyp","abc","abc"
Set RSCategories = Conn.Execute("Select CategoryName " _
& "from Categories Order By CategoryName")<P>Do Until RSCategories.EOF
GetCategories = GetCategories & "<OPTION VALUE=""" _
& RSCategories("CategoryName") _
& """>" & RSCategories("CategoryName") _ "</Option>"
RSCategories.MoveNext
Loop
End Function<P><B>End Class</B>

Then hopefully it should work. You don't really have to use a class here either. You could just include that function as is in your main page. Which would be:

code:<HR>
Code:
<%@ Language=VBScript %>
<%Option Explicit%>
<%
Function GetCategories()
Dim Conn As New ADODB.Connection
Dim RSCategories As ADODB.Recordset<P>Conn.Open "fyp","abc","abc"
Set RSCategories = Conn.Execute("Select CategoryName " _
& "from Categories Order By CategoryName")<P>Do Until RSCategories.EOF
GetCategories = GetCategories & "<OPTION VALUE=""" _
& RSCategories("CategoryName") _
& """>" & RSCategories("CategoryName") _ "</Option>"
RSCategories.MoveNext
Loop
End Function 
%>
<Select Name = "Category">
<%
Response.Write GetCategories()
%>
</Select><P>

Did that work?
 

E3

Ars Centurion
387
<%@ Language=VBScript %>

<%Option Explicit
Dim MyAuction
Set MyAuction = New AuctionData
%>
<Select Name = "Category">
<%
Response.Write MyAuction.GetCategories
%>
</Select>

<%@ Language=VBScript %>
<Script Language = VBScript>
Option Explicit

Class AuctionData
Public Function GetCategories()
Dim Conn As New ADODB.Connection
Dim RSCategories As ADODB.Recordset

Conn.Open "fyp","abc","abc"
Set RSCategories = Conn.Execute("Select CategoryName " _
& "from Categories Order By CategoryName")

Do Until RSCategories.EOF
GetCategories = GetCategories & "<OPTION VALUE=""" _
& RSCategories("CategoryName") _
& """>" & RSCategories("CategoryName") _ "</Option>"
RSCategories.MoveNext
Loop
End Function
End Class


Error Type:
Microsoft VBScript runtime (0x800A01F4)
Variable is undefined: 'AuctionData'
/auctionmenu.asp, line 5


hmmm, still it doesn't work.
 

E3

Ars Centurion
387
hey look wat i found

Some Caveats

The lifetime of a VBScript class is limited to the lifetime of the page. The VBScript engine itself is created and destroyed on each page, therefore, so are any classes you instantiate. This will limit your ability to place these objects in Session or Application scope


http://www.aspzone.com/articles/john/VBScriptClasses/

Now I m terribly excited. Does this means using #include file will save all my problems???

hmm
 

E3

Ars Centurion
387
<Script Language = VBScript>
Option Explicit

Class AuctionData
Public Function GetCategories()
Dim Conn As New ADODB.Connection
Dim RSCategories As ADODB.Recordset

Conn.Open "fyp","abc","abc"
Set RSCategories = Conn.Execute("Select CategoryName " _
& "from Categories Order By CategoryName")

Do Until RSCategories.EOF
GetCategories = GetCategories & "<OPTION VALUE=""" _
& RSCategories("CategoryName") _
& """>" & RSCategories("CategoryName") _ "</Option>"
RSCategories.MoveNext
Loop
End Function

End Class
</SCRIPT>

<%
Dim MyAuction
Set MyAuction = New AuctionData
%>
<HTML>
<HEAD>
<TITLE>Test- Test</TITLE>
</HEAD>
<BODY>
<Select Name = "Category">
<%
Response.Write MyAuction.GetCategories
%>
</Select>

</Body>
</HTML>


Error Type:
Microsoft VBScript runtime (0x800A01FA)
Class not defined: 'AuctionData'
/auctiondata.asp, line 26


:confused: :confused: :confused:

Seems that the server can't call client side methods so I altered

<Script Language = VBScript>
Option Explicit

Class AuctionData
Public Function GetCategories()
Dim Conn As New ADODB.Connection
Dim RSCategories As ADODB.Recordset

Conn.Open "fyp","abc","abc"
Set RSCategories = Conn.Execute("Select CategoryName " _
& "from Categories Order By CategoryName")

Do Until RSCategories.EOF
GetCategories = GetCategories & "<OPTION VALUE=""" _
& RSCategories("CategoryName") _
& """>" & RSCategories("CategoryName") _ "</Option>"
RSCategories.MoveNext
Loop
End Function

End Class

Dim MyAuction
Set MyAuction = New AuctionData

</SCRIPT>


<HTML>
<HEAD>
<TITLE>Test- Test</TITLE>
</HEAD>
<BODY>
<Select Name = "Category">
<%
Response.Write MyAuction.GetCategories
%>
</Select>

</Body>
</HTML>

Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: ''
/auctiondata.asp, line 36


The codes originally used by the book for declaring a class is
"Quoted:component instantiated with app.class string Auction.AuctionData"

<%
option Explicit
Dim MyAuction
Set MyAuction = server.CreateObject("Auction.AuctionData")
%>
<Select Name= "Category">
<% Response.Write MyAuction.GetCategories
%>
</select>

But I m not sure what the app.class , app is about!!! and
got this error
Error Type:
Microsoft VBScript compilation (0x800A0400)
Expected statement
/auctiondata.asp, line 27
option Explicit


:( :( :( :( :( :( :( /consoles, dun lost hope, E3.

[This message was edited by E3 on January 21, 2002 at 08:09.]
 

wookiecrisp

Ars Scholae Palatinae
891
Ok... you have some issues to work out... I tried the code, and everything seems fine. Put the below in one page, an .asp page, and try it out.

code:<HR>
Code:
<% @Language="VBScript" %>
<% Option Explicit %>
<% Response.Buffer = True %>
<% Response.Expires = 0 %>
<%
Class AuctionData
	Public Function GetCategories()
		Dim Conn
		Dim RSCategories
		
		Set Conn = Server.CreateObject("ADODB.Connection")
		
		Conn.Open "fyp","abc","abc"
		Set RSCategories = Conn.Execute("Select CategoryName " & "from Categories Order By CategoryName")<P>		Do Until RSCategories.EOF
			GetCategories = GetCategories & "<OPTION VALUE=""" & RSCategories("CategoryName") & """>" & RSCategories("CategoryName") & "</Option>"
			RSCategories.MoveNext
		Loop
		
		RSCategories.Close
		set RSCategories = nothing
		Conn.Close
		Set Conn = Nothing
		
	End Function 
End Class
%><P>
<HTML>
<HEAD>
<TITLE>Test- Test</TITLE>
</HEAD>
<BODY>
<Select Name = "Category">
<%
Dim MyAuction
Set MyAuction = New AuctionData
Response.Write MyAuction.GetCategories
%>
</Select>
</Body>
</HTML>
 

E3

Ars Centurion
387
I decided to switch the class into a server component.
However I wanted to compile the class as a .dll file, it gives an error " Dim Conn As New ADODB.Connection" "User defined type not defined"

Any idea on how to go about it??

When I started VB6,it asks for the kind of project I want to create,
Is ActiveX DLL the correct one?
Is there any particular library that I need to enable references to use ADODB objects?


sorry for all the trouble. :rolleyes:
 

wookiecrisp

Ars Scholae Palatinae
891
Why did you decide to go the .dll route? Did the last code I give work out for you?

Yes, ActiveX DLL is the right choice.

As for your problem, try doing it in 2 lines instead of 1:

code:<HR>
Code:
Dim Conn As ADODB.Connection
Set Conn = New ADODB.Connection

Try doing a search on Google as well, there is a wealth of information.
 
Status
Not open for further replies.