Classes query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ziycon
    Contributor
    • Sep 2008
    • 384

    Classes query

    I'm well versed on classes and OOP in PHP and Java but can't for the life of me get it to working in ASP classic using VB.

    I'm getting no errors, a blank page is displaying.

    I have the below in two files. If anyone can point me in the right direction I'd much appreciate it.

    Default.asp
    Code:
    <%@ Language="VBSCRIPT" %>
    <!-- #include file="dbConnection.asp" -->
    <%
    	Dim odbConnection 'As New dbConnection
    
    	Set odbConnection = New dbConnection
    %>
    <html>
    <head>
    <title>ASP Test</title>
    </head>
    <body>
    <%
    	odbConnection.dbOpen
    	odbConnection.getStatus
    	odbConnection.dbClose
    %>
    </body>
    </html>
    dbConnection.as p
    Code:
    <%
    Class dbConnection
    	Private conn
    	Private conn_string
    	Private status
    
    	Private Sub Class_Initialize() 
    		
    	End Sub
    
    	Public dbOpen()
    		Set conn = Server.CreateObject("ADODB.Connection")
    		conn.conn_string = "Driver={MySQL ODBC 5.1 Driver};SERVER=localhost;Port=3306;Database=db;Uid=user;Pwd=pass"
    		conn.Open
    		status = 1
    	End Sub
    
    	Public dbClose()
    		conn.Close
    		status = 0
    	End Sub
    
    	Public getStatus()
    		If status = 1 Then
    			Response.Write "Database connection up"
    		Else
    			Response.Write "Database connection down"
    		End If
    	End Sub
    	
    Private Sub Class_Terminate()
     
    End Sub
    
    End Class
    %>
  • ziycon
    Contributor
    • Sep 2008
    • 384

    #2
    I'm actually getting the below error now.
    Error Type:
    Microsoft VBScript compilation (0x800A03EA)
    Syntax error
    /dbConnection.as p, line 12
    Set conn = Server.CreateOb ject("ADODB.Con nection")

    Comment

    • ziycon
      Contributor
      • Sep 2008
      • 384

      #3
      Got the classes working.

      Comment

      • jhardman
        Recognized Expert Specialist
        • Jan 2007
        • 3405

        #4
        Besides your syntax errors, your biggest mistake is your assumption that VBScript is object oriented. It is not, it is linearly-executed code like BASIC. It has some simple oop support, but that's it.

        Anyway, glad you found a solution.

        Jared

        Comment

        Working...