'******** BEGIN CONSTANTS ********
'Response.Write Server.MapPath("links.htm")
Const LINKS_FILE = "D:\Webs\asp101\www\samples\links.htm"
'******** END CONSTANTS ********
'******** BEGIN FUCTION DECLARATIONS ********
Function GetLinksFileAsString()
Dim objFSO, objInputFile
Dim strTemp ' as String
Set objFSO = Server.CreateObject
("Scripting.FileSystemObject")
Set objInputFile = objFSO.OpenTextFile(LINKS_FILE)
strTemp = objInputFile.ReadAll
objInputFile.Close
Set objInputFile = Nothing
Set objFSO = Nothing
GetLinksFileAsString = strTemp
End Function
Function GetLinkCount(strFullLinksFileText)
Dim I ' as Integer
I = 1
Do While Instr(1, strFullLinksFileText, "<!-- Begin Link "
& I & " -->") <> 0
I = I + 1
Loop
GetLinkCount = I - 1
End Function
' Not called directly by runtime code!
' - wrapped by the next few functions to encapsulate parameters
Function GetHTMLBetweenStrings(strFullLinksFileText, strStart, strEnd)
Dim iStart, iEnd
iStart = Instr(1, strFullLinksFileText, strStart) + Len
(strStart)
iEnd = Instr(iStart, strFullLinksFileText, strEnd)
GetHTMLBetweenStrings = Mid(strFullLinksFileText, iStart,
iEnd - iStart)
End Function
Function GetLinkHTML(iLinkNumber, strFullLinksFileText)
GetLinkHTML = GetHTMLBetweenStrings
(strFullLinksFileText, "<!-- Begin Link " & iLinkNumber & " -->", "<!-
- End Link " & iLinkNumber & " -->")
End Function
Function GetCommentHTML(iLinkNumber, strFullLinksFileText)
GetCommentHTML = GetHTMLBetweenStrings
(strFullLinksFileText, "<!-- Begin Comment " & iLinkNumber & " --
>", "<!-- End Comment " & iLinkNumber & " -->")
End Function
Function GetHTMLBetweenLinkAndComment(iLinkNumber,
strFullLinksFileText)
GetHTMLBetweenLinkAndComment = GetHTMLBetweenStrings
(strFullLinksFileText, "<!-- End Link " & iLinkNumber & " -->", "<!--
Begin Comment " & iLinkNumber & " -->")
End Function
Function GetHTMLBetweenLinks(iPreviousLinkNumber,
strFullLinksFileText)
GetHTMLBetweenLinks = GetHTMLBetweenStrings
(strFullLinksFileText, "<!-- End Comment " & iPreviousLinkNumber & " -
->", "<!-- Begin Link " & iPreviousLinkNumber + 1 & " -->")
End Function
Function GetHeaderHTML(strFullLinksFileText)
Dim strTemp
Dim strEnd
Dim iStart, iEnd
strTemp = strFullLinksFileText
strEnd = "<!-- Begin Link 1 -->"
iStart = 1
iEnd = Instr(iStart, strFullLinksFileText, strEnd)
strTemp = Mid(strTemp, iStart, iEnd - iStart)
GetHeaderHTML = strTemp
End Function
Function GetFooterHTML(strFullLinksFileText, iLinkCount)
Dim strTemp
Dim strStart
Dim iStart, iEnd
strTemp = strFullLinksFileText
strStart = "<!-- End Comment " & iLinkCount & " -->"
iStart = Instr(1, strFullLinksFileText, strStart) + Len
(strStart)
iEnd = Len(strFullLinksFileText) + 1
strTemp = Mid(strTemp, iStart, iEnd - iStart)
GetFooterHTML = strTemp
End Function
Sub WriteLinksFileToDisk(strFullLinksFileText)
Dim objFSO, objLinksFile
Dim strTemp ' as String
Set objFSO = Server.CreateObject
("Scripting.FileSystemObject")
Set objLinksFile = objFSO.CreateTextFile(LINKS_FILE, True)
objLinksFile.Write strFullLinksFileText
objLinksFile.Close
Set objLinksFile = Nothing
Set objFSO = Nothing
End Sub
'******** END FUCTION DECLARATIONS ********
'******** BEGIN RUNTIME CODE ********
Dim strInput ' as String - will contain the whole links html page!
Dim strOutput ' as String - will contain modified version!
Dim strTemp ' as String - used for string building etc.
Dim iLinkCount ' as Integer - number of lin