July 28, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Pseudo-Objects in Active Server Pages

  • October 14, 1999
  • By Thornton Rose
  • Send Email »
  • More Articles »

<%
' DatabaseObj.asp - Program to show database version of pseudo-object called
' "Car".
option explicit
%>

NOTE: include file="db.inc"
NOTE: include file="car.inc"



   DatabaseObj.asp




		
<%
dim strConn  ' Connection string
dim carList  ' List of cars
dim car      ' Car object
dim items    ' Array of car objects
dim result   ' Result code
dim i        ' Counter

' Specify database connection.

strConn = "DSN=CarDB;UID=;PWD="

' Put some car objects in the database.

CreateCars strConn
Response.Write vbCrLf

' Load and show a list of Cars that are newer than 1990, ordered by make.

set carList = Car_Load(strConn, "year > 1990", "make, model, year")

Response.Write "Cars newer than 1990:" & vbCrLf
ShowCarList carList
Response.Write vbCrLf

' Make the 1990 and later cars blue.

items = carList.Items()

for i = 0 to UBound(items)
   set car = items(i)
   car("color") = "blue"
   result = Car_Update(strConn, car)
next

' Show the cars again.

Response.Write "Blue cars newer than 1990:" & vbCrLf
ShowCarList carList
Response.Write vbCrLf

' Delete the 1997 Geo Prizm.

set car = carList("1003")
result = Car_Delete(strConn, car)

ShowCar car
Response.Write " deleted." & vbCrLf & vbCrLf

' Load the list of all cars, then show it.

set carList = Car_Load(strConn, "", "make, model, year")

Response.Write "All cars that are left:" & vbCrLf
ShowCarList carList

' -----------------------------------------------------------------------------

' CreateCars(): Populate the database with some cars.
'
sub CreateCars(strConn)
   dim objCar
   
   ' Car 1

   set objCar = Car_New()
   objCar("VIN")   = "1001"
   objCar("make")  = "Toyota"
   objCar("model") = "Corolla"
   objCar("color") = "white"
   objCar("year")  = 1991

   Car_Insert strConn, objCar

   ShowCar objCar
   Response.Write " inserted." & vbCrLf

   ' Car 2

   set objCar = Car_New()
   objCar("VIN")   = "1002"
   objCar("make") = "Volkswagen"
   objCar("model") = "Beetle"
   objCar("color") = "red"
   objCar("year") = 1965

   Car_Insert strConn, objCar

   ShowCar objCar
   Response.Write " inserted." & vbCrLf

   ' Car 3

   set objCar = Car_New()
   objCar("VIN")   = "1003"
   objCar("make") = "Geo"
   objCar("model") = "Prizm"
   objCar("color") = "green"
   objCar("year") = 1997

   Car_Insert strConn, objCar

   ShowCar objCar
   Response.Write " inserted." & vbCrLf
end sub

' ShowCarList(): Show the given list of cars.
'
sub ShowCarList(list)
   dim i
   dim items
   dim car

   ' Get an array of the items.
   
   items = list.Items()

   ' Loop through the array.

   for i = 0 to UBound(items)
      ' Get the car.
      
      set car = items(i)

      ' Show the car.
      
      Response.Write "car " & (i + 1) & " = "
      ShowCar car
      Response.Write vbCrLf
   next
end sub

' ShowCar(): Shows the given car.
'
sub ShowCar(car)
   Response.Write "[" & car("year") & " " & car("make") & " " & _
      car("model") & ", " & car("color") & "]"
end sub
%>





Page 4 of 11



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel