New to Classes - Can I do this

Results 1 to 2 of 2

Thread: New to Classes - Can I do this

  1. #1
    Shaun Shull Guest

    Default New to Classes - Can I do this

    I am making an online movie store and am trying to use classes. Is this code below possible or is there something that I must change in it?<BR><BR>&#060;%@ Language=VBScript %&#062;<BR>&#060;%<BR>Class DbAccess<BR><BR> Public dbDsn<BR> Public Columns<BR> Public Table<BR> Public Param<BR><BR> Public SQL<BR> Public DBConn<BR> Public RS<BR> <BR> Set DBConn = Server.CreateObject("ADODB.Connection")<BR> DBConn.Open dbDsn<BR> SQL = "select "&Columns&" from " & Table & " " & Param<BR> Set RS = DBConn.execute(SQL)<BR> <BR> DBConn.Close<BR> RS.Close<BR> <BR>End Class<BR><BR><BR><BR><BR><BR>Class MovieView<BR><BR> Public dbDsn<BR> Public movieTable<BR> Public movieIdColumn<BR> <BR> Public theId<BR><BR> Private dbData = new DbAccess<BR> dbData.dbDsn = movieDsn<BR> dbData.Columns = "*"<BR> dbData.Table = movieTable<BR> dbData.Param = "where " & movieIdColumn & " = " & theId<BR> <BR> Public movieId = dbData.RS("")<BR> Public movieType = dbData.RS("")<BR> Public movieName = dbData.RS("")<BR> Public movieCategory = dbData.RS("")<BR> Public movieActors = dbData.RS("")<BR> Public movieStudio = dbData.RS("")<BR> Public movieDirectors = dbData.RS("")<BR> Public movieDate = dbData.RS("") <BR> <BR> Set dbData.DBConn = Nothing<BR> Set dbData.RS = Nothing<BR> <BR>End Class<BR>%&#062;

  2. #2
    Join Date
    Dec 1969

    Default No...

    You can&#039;t have *CODE* in the body of a CLASS. You *must* put the code inside a function or sub. If you want the code to be executed when an instance of the class is created using NEW, then put the code into a PUBLIC SUB named Class_Initialize. Look up Class_Initialize in the VBS docs.<BR><BR>Also...if you will open the connection, get the record set, then close the connection, then the connection should *DEFINITELY NOT* be PUBLIC. In fact, it shouldn&#039;t even be declared at Class scope...just a simple DIM inside the Function/Sub.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts