The main purpose of the vacancy page is to retrieve a list of rental properties from a given region that have vacancies during a time period specified by the user. The user also specifies the types of rental unit they are interested in. Vacancy data is stored in six text files that correspond to the six classes of rental unit represented by check boxes in the vacancy page.
When the user presses the submit button, the asp page generated lists all of the properties in each category that have vacancies for the given dates. Notice that since this list can be fairly large, there are links to the beginning of each category.
The first part of the page retrieves the date from the VacancyForm. All of the date information is stored as integers. This information is immediately displayed in the page that is generated by the Response.Write lines. The setDate function creates a string with a date in the form "mm/dd/yy" with the quotes included in the string. This is the format of all dates in the files listing vacancies.
<H1>Vacancy Information</H1>
<P>Arriving on: <B>
<%
intArriveMonth = Request("startMonth")
intArriveDate = Request("startDate")
intArriveYear =Request("startYear")
Response.Write( month(intArriveMonth-1)&" "& intArriveDate &", "& intArriveYear)
strBegin = setDate(intArriveMonth,intArriveDate,intArriveYear)
%>
</B><BR> Leaving on:
<B><%
intLeaveMonth = Request("endMonth")
intLeaveDate = Request("endDate")
intLeaveYear =Request("endYear")
Response.Write( month(intLeaveMonth-1)&" "& intLeaveDate &", "& intLeaveYear)
strEnd = setDate(intLeaveMonth,intLeaveDate,intLeaveYear)
The function setDate must make sure that the number of digits in the day and month fields is two, and that the fields are separated by a "/". In addition, only the last two digits of the year are needed, so the VBScript function Right is called to get the two rightmost digits. Notice that & is used for concatenation. While Visual Basic allows you to use + to concatenate strings, + is reserved for addition in VBScript. Finally the result is returned by the last statement (setDate=strResult) by setting the name of the function equal to the result that gets returned.
strQuote ="""" Function setDate(intMonth,intDate,intYear) Dim strResult strResult = "" if intMonth < 10 then strResult = "0" end if strResult = strResult & intMonth&"/" if intDate < 10 then strResult = strResult & "0" end if strResult = strResult & intDate&"/"&Right(intYear,2) setDate = strResult End Function
The next section is used to retrieve the types of properties that are requested and setup the links to the section where vacancies for a given property type are listed. Notice if a checkbox is checked, the string "on" is returned.
For each type of property requested, the getProperties function retrieves the list of properties as a string. This string is then written to the page.
if strHotel = "on" then
Response.Write("<H2><A NAME ="&strQuote&"HOTELS"&strQuote&">Hotels</A> ,
Motels, and Inns</H2>")
strProperties= getProperties(strPath,"Table1.txt",strBegin,strEnd)
Response.Write(strProperties)
end if
Here is the whole asp page. Note some statements are extended over two lines so you can print them. In the real asp page this statements are on one line.
<BODY>
<!-- **************** Heading information here ********************** -->
<!-- ******************** Show the list of properties with vacancies here *************** -->
<!-- Retrieve the information and prepare the dates -->
<H1>Vacancy Information</H1>
<P>Arriving on: <B>
<%
intArriveMonth = Request("startMonth")
intArriveDate = Request("startDate")
intArriveYear =Request("startYear")
Response.Write( month(intArriveMonth-1)&" "& intArriveDate &", "& intArriveYear)
strBegin = setDate(intArriveMonth,intArriveDate,intArriveYear)
%>
</B><BR> Leaving on:
<B><%
intLeaveMonth = Request("endMonth")
intLeaveDate = Request("endDate")
intLeaveYear =Request("endYear")
Response.Write( month(intLeaveMonth-1)&" "& intLeaveDate &", "& intLeaveYear)
strEnd = setDate(intLeaveMonth,intLeaveDate,intLeaveYear)
<!-- Set the length of February in case of leep year -->
if intArriveMonth >1 and intLeaveYear mod 4 = 0 then
monthEnds(1)=29
else
if intArriveYear mod 4 = 0 then
monthEnds(1)=29
end if
end if
<!--Get the name of the county (pathString) and find out which types of rentals required -->
strPath = Request("pathString")
Dim strHotel
strHotel = Request("Hotel")
Dim strResort
strResort= Request("resort")
Dim strbAndB
strbAndB= Request("bAndB")
Dim strCottage
strCottage= Request("cottage")
Dim strCampground
strCampground= Request("campground")
Dim strMarina
strMarina= Request("marina")
<!-- Set up links to the information -->
if strHotel = "on" then
Response.Write("<BR><A HREF = "&strQuote&"#HOTELS"&strQuote&_
">Hotels, Motels and Inns</A> ")
end if
if strResort = "on" then
Response.Write("<BR><A HREF = "&strQuote&"#RESORTS"&strQuote&">Resorts</A> ")
end if
if strbAndB = "on" then
Response.Write("<BR><A HREF = "&strQuote&"#BANDB"&strQuote&_
">Bed and Breakfasts</A> ")
end if
if strCottage = "on" then
Response.Write("<BR><A HREF = "&strQuote&"#COTTAGE"&strQuote&">Cottages</A> ")
end if
if strCampground = "on" then
Response.Write("<BR><A HREF = "&strQuote&"#CAMPGROUND"&strQuote&">Campgrounds</A> ")
end if
if strMarina = "on" then
Response.Write("<BR><A HREF = "&strQuote&"#MARINA"&strQuote&">Marinas</A> ")
end if
%>
</B>
</P>
<%
<!-- Retrive lists of properties of the appropriate types and write the results -->
if strHotel = "on" then
Response.Write("<H2><A NAME ="&strQuote&"HOTELS"&strQuote& _
">Hotels</A> , Motels, and Inns</H2>")
strProperties= getProperties(strPath,"Table1.txt",strBegin,strEnd)
Response.Write(strProperties)
end if
if strResort = "on" then
Response.Write("<H2><A NAME ="&strQuote&"RESORTS"&strQuote&">Resorts</A> </H2>")
strProperties= getProperties(strPath,"Table2.txt",strBegin,strEnd)
Response.Write(strProperties)
end if
if strbAndB = "on" then
Response.Write("<H2><A NAME ="&strQuote&"BANDB"&strQuote& _
">Bed</A> and Breakfast</H2>")
strProperties= getProperties(strPath,"Table3.txt",strBegin,strEnd)
Response.Write(strProperties)
end if
if strCottage = "on" then
Response.Write("<H2><A NAME ="&strQuote&"COTTAGE"&strQuote&">Cottages</A> </H2>")
strProperties= getProperties(strPath,"Table4.txt",strBegin,strEnd)
Response.Write(strProperties)
end if
if strCampground = "on" then
Response.Write("<H2><A NAME ="&strQuote&"CAMPGROUND"& _
strQuote&">Campgrounds</A> </H2>")
strProperties= getProperties(strPath,"Table5.txt",strBegin,strEnd)
Response.Write(strProperties)
end if
if strMarina = "on" then
Response.Write("<H2><A NAME ="&strQuote&"MARINA"&strQuote&">Marinas</A> </H2>")
strProperties= getProperties(strPath,"Table6.txt",strBegin,strEnd)
Response.Write(strProperties)
end if
%>
<!-- ******************** This is the bottom of the page ********************** -->
</BODY>
Every property in a given class is contained in one file. The information for each property consists of strings separated by commas and terminated with an end of line marker. This means all of the information for one property is retrieved by a single read. The first data field in a property record is the name of the property. This is followed by its location and its home page. The rest of the record is a list of all of the days that still have vacancies. Each date is listed as a string and is separated from the next date in the record by a comma. If a date is missing, there is no vacancy on that date. Part of one record is given here.
"Americinn Motel & Suites","Ashland","IL6162.HTM","07/20/00","07/21/00","07/22/00","07/23/00","07/24/00","07/25/00",...
Recall that when this information is read, it is all contained in one string, so the quotes you see here are all characters contained in the string retrieved from the file. To see if a property has a reservation for a period of time, it was only necessary to create a string representing the list of dates and check to see if that string is in the current property record. The first problem is to create a string like this: ""07/21/00","07/22/00","07/23/00",". For dates in a single month this is relatively easy, but for dates that extend over multiple months and/or years it is a bit more complicated.
Function getStayString(strFrom, strUntil)
Dim strGenerate, startMonth, startDate, startYear, endMonth, endDate, endYear
Dim strQuote, strDate,strQuoteComma
Dim intEndDate, intEndMonth, intEndYear
Dim intDate, intMonth, intYear
'strQuoteComma is the deliminator between days
strQuote = """"
strQuoteComma = strQuote & "," & strQuote
'Get the numerical values of the days, months and years
startMonth = Mid(strFrom, 1, 2)
startDate = Mid(strFrom, 4, 2)
startYear = Mid(strFrom, 7, 2)
endMonth = Mid(strUntil, 1, 2)
endDate = Mid(strUntil, 4, 2)
endYear = Mid(strUntil, 7, 2)
'These are not actually integers here, but are used like integers later.
intEndDate = endDate
intEndMonth = endMonth
'Start the string here
strDate = strQuote & strFrom & strQuote
'Create integer values of the important date parts. Used to generate the test string
intEndDate = CInt(endDate)
intDate = CInt(startDate)
intMonth = CInt(startMonth)
intYear = CInt(startYear)
'Loop through the time period requested, adding one day each time through
Do While strDate <> strQuote & strUntil & strQuote
' Add the current date string and the comma
strGenerate = strGenerate & strDate
strGenerate = strGenerate & ","
'Start the next days date with a quote
strDate = strQuote
'Increment the day unless the end of the month then set the day to 1
'and increment month. If the end of the year, set month to 1 and increment the year.
If intDate < monthEnds(intMonth - 1) Then
intDate = intDate + 1
Else
intDate = 1
If intMonth < 12 Then
intMonth = intMonth + 1
Else
intMonth = 1
intYear =intYear + 1
End If
End If
'If month is one digit add zero
If intMonth < 10 Then
strDate = strDate & "0"
End If
strDate = strDate & intMonth& "/"
'If day is one digit add zero
If intDate < 10 Then
strDate = strDate & "0"
End If
' construct the date part and make sure to concatenate a 0 in front of year if too small
strDate = strDate & intDate & "/"
If startYear < 10 Then
strDate = strDate & "0"
End If
'Add the quote to the end of the
strDate = strDate & intYear & strQuote
Loop
getStayString = strGenerate
End Function
The search is relatively simple. First create a file object so you can retrieve the information. This is done with boiler plate code noted below. Next get the string representing the dates requested and get rid of the header for the file (it gives the type of data in the file). Then while not at the end of the file, check to see if the test list of days is found in the current property. If it is, retrieve the name, location and home page URL for the property. Then create html code that will create a link to the property surrounding the name of the property.
Function getProperties(strPath, strFileIn, strArrive, strLeave)
Dim objFileSystem, objFile
Dim strOneLine, strURL, strOutput, strStayPattern, strQuote,strQuoteCommaQuote
Dim blnNoVacancies
blnNoVacancies = True
strOutput = ""
strQuote = """"
strQuoteCommaQuote= strQuote&","&strQuote
'Open the appropriate file. Note you must use Set when assigning objects
strURL = "http://www.innline.com/" & strPath&"/"
Set objFileSystem = CreateObject("Scripting.FileSystemObject")
Set objFile = objFileSystem.OpenTextFile("D:\virtualservers\Innline.com\"&strPath&"\"&strFileIn)
'Get the test string for this reservation request
strStayPattern = getStayString(strArrive, strLeave)
strOneLine = objFile.Readline 'get rid of header
'Loop through all properties
Do While Not objFile.AtEndOfStream
'Read a property
strOneLine = objFile.Readline 'property vacancy data
Dim intLocation
intLocation = InStr(1, strOneLine, strStayPattern)'did you match a vacancy
If intLocation > 0 Then
blnNoVacancies = False 'found at least one vacancy
'Get property name
Dim intFrom
intFrom = InStr(1, strOneLine, strQuoteCommaQuote, 1)
Dim strPropertyName
strPropertyName = Mid(strOneLine, 2, intFrom - 2)
intFrom = intFrom
'get property city
Dim intStart
intStart = intFrom + 1
intFrom = InStr(intStart, strOneLine, strQuoteCommaQuote, 1)
Dim strCity
strCity = Mid(strOneLine, intStart + 2, intFrom - intStart - 2)
'get property html;
intFrom = intFrom + 2
intStart = intFrom
intFrom = InStr(intFrom, strOneLine, strQuoteCommaQuote)
Dim strHtml
strHtml = strURL & Mid(strOneLine, intStart+1, intFrom-intStart-1)
'Add this property to the listing
strOutput = strOutput & "<BR><FONT SIZE=+1>" & _
"<A HREF=" & strQuote & strHtml & strQuote & ">" & _
strPropertyName & "</A></FONT> " & strCity & vbNewLine
End If 'if dates not available do nothing.
Loop
'Close the file and return the string
objFile.Close
getProperties = strOutput
End Function