VB Code:
Option Explicit
Declare Function GetStdHandle Lib "kernel32" (ByVal nStdHandle As Long) As Long
Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, lpOverlapped As Any) As Long
Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, ByVal lpBuffer As String, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, lpOverlapped As Any) As Long
Public Const STD_INPUT_HANDLE = -10&
Public Const STD_OUTPUT_HANDLE = -11&
Public Const FILE_BEGIN = 0&
Public hStdIn As Long ' handle of Standard Input
Public hStdOut As Long ' handle of Standard Output
Public Sub Main()
Dim Count As Long, Buff As String
hStdIn = GetStdHandle(STD_INPUT_HANDLE)
hStdOut = GetStdHandle(STD_OUTPUT_HANDLE)
Send "HTTP/1.0 200 OK"
Send "Content-type: text/html" & vbCrLf
Open App.Path & "\TestFile.txt" For Binary Access Read As #1
Buff = String(LOF(1), 0)
Get #1, , Buff
Count = Val(Buff) + 1
Close #1
Open App.Path & "\TestFile.txt" For Binary Access Write As #1
Put #1, , CStr(Count)
Close #1
Send "<html><body><h1>Hello world !</h1>"
Send "<br><br><br>"
Send "This page was loaded " & Count & " time" & IIf(Count = 1, "", "s") & "."
Send "</body></hrml>"
End
End Sub
Private Function Send(ByVal Str As String) As Long
Dim lBytesWritten As Long
Str = Str & vbCrLf
WriteFile hStdOut, Str, Len(Str), lBytesWritten, ByVal 0&
Send = lBytesWritten
End Function