The online racing simulator
ASP Webpage [LFSLapper]
Hi All,
I need an ASP Webpage creating that will read the PB.txt thats created by LFSLapper. The page will update my Access DB every every X minutes or on every access of the data display page.

I can do the rest of the ASP to display the information just not got a clue how to access PB.txt using ASP.

Just noticed LFSLapper has a .PDB file also that maybe easier to use.

Thanks in advance for any help
If you Google 'ASP Text file', You can find some very good information of how to read/write text files with ASP.

http://www.codeproject.com/KB/asp/readfile.aspx

HTH
Hi,
I really cannot work it out how to read each line and set it as a variable so it can then be written to DB. Can someone give me an example of 1 line and I can do the rest.

<%
Set fileObj=Server.CreateObject("Scripting.FileSystemObject")
Set listFile=fileObj.OpenTextFile(Server.MapPath("/cgi-bin/PB.txt"), 1)
listfile.skipline
do while listFile.AtEndOfStream = false
Response.Write(listFile.ReadLine)
Response.Write("<br>")
loop
listFile.Close
Set listFile=Nothing
Set fileObj=Nothing
%>

This reads PB.txt and writes it to the page. I need to read each line and set a variable for each line and thats got me baffled.

Thanks
#5 - SamH
I've never used lapper, so I have no idea what the content of the file is. If you'll post a few example entries, it shouldn't be difficult for one of us to write a few lines to lift the information out of the text file, separate it out into fields and put it into a database.
USERNAME 02
toldo
Leslie
6
5/29/2008
10:08 PM
XRR
1.48.90
AS3
0.47.73
0.00.00
0.00.00
0.47.66
0.00.00
0.00.00
1.01.17
rudymarshall
^7[^3TURT^7] R^3u^7d^3y
49
6/2/2008
4:09 PM
XRR
1.42.85
AS3
0.45.29
0.00.00
0.00.00
0.45.11
0.00.00
0.00.00
0.57.50
stein-andre
^1=NSP= ^4Stein
1
19/05/2008
12:49
XRR
2.03.26
AS3
0.56.97
0.00.00
0.00.00
0.48.35
0.00.00
0.00.00
1.06.29

And goes on and on and on lol

Thanks
#7 - SamH
rudymarshall
^7[^3TURT^7] R^3u^7d^3y
49
6/2/2008
4:09 PM
XRR
1.42.85
AS3
0.45.29
0.00.00
0.00.00
0.45.11
0.00.00
0.00.00
0.57.50

This looks like a record block. I'm assuming it's LFS Username, Player Name, Number of laps?, Last raced date?, Last raced time?, Car raced, best lap?, track.... I haven't a clue what the others are..

If someone can shed light on those, I can quickly build an ASP page to stuff all this data into a database.
Actual splits on pb lap and best possible splits?
-
(SamH) DELETED by SamH : Goofed
#9 - SamH
This is completely untested code, but it should get you close to where you want to be. It also stores laptimes and sectors (if that's what they are) as text. Ideally you should convert Split1-Split7 into milliseconds and store them as numeric. I reckon you'll be capable of that kind of modification though. (Re-posted due to glaring error)


<%
' *************************************************************
' * Reads LFS Lapper PB.txt and feeds content into a database *
' *************************************************************
' To use this ASP page, you will need the following:
' 1) A connection string to connect to your database.
' 2) A database table with the following structure. Default
' values should do (untested)
' RecordID, Text, key, no duplicates
' Username, Text
' PlyName, Text
' TotLaps, Numeric
' LastDate, Text
' LastTime, Text
' Car, Text
' LapTime, Text
' Track, Text
' Split1, Text
' Split2, Text
' Split3, Text
' Split4, Text
' Split5, Text
' Split6, Text
' Split7, Text
' 3) The full path to your PB.txt file, or its location in
' your website directory.
' *************************************************************

Application("dbConnHold")=true
' Don't allow other pages to query the database table while Application("dbConnHold")=true
' strFileName = Server.MapPath("/PB.txt") ' Uncomment and correct if PB.txt is available in your website directory.
strFileName = "C:\PathTo\YourLapper\PB.txt"
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set TS = objFSO.OpenTextFile(strFileName, 1, False)
DitchContent=DoSQLCommand("DELETE FROM database.Table") ' Wipe the existing data from the database, ready to read in new content.
If DitchContent <> True Then
Response.Write("Database connection problem. Operation cancelled.")
Application("dbConnHold")=false ' Release the database table for reading by other pages.
Response.End()
End If
If Not TS.AtEndOfStream Then
NotUsed = TS.ReadLine ' Ditch the first line. It's not part of the driver records.
Do While Not TS.AtendOfStream
' Read each record block into memory. Since we know the uniform structure of records in PB.txt, we can uniformly read in the correct number of lines in a cycle.
Username = TS.ReadLine
PlyName = TS.ReadLine
TotLaps = TS.ReadLine
LastDate = TS.ReadLine
LastTime = TS.ReadLine
Car = TS.ReadLine
LapTime = TS.ReadLine
Track = TS.ReadLine
Split1 = TS.ReadLine
Split2 = TS.ReadLine
Split3 = TS.ReadLine
Split4 = TS.ReadLine
Split5 = TS.ReadLine
Split6 = TS.ReadLine
Split7 = TS.ReadLine
RecordID = Username & ":" & Track & ":" & Car

If Username <> "" Then ' No username error
' Place the record into the database.
AddUser=DoSQLCommand("INSERT INTO database.Table VALUES('" & RecordID & "','" & Username & "','" & PlyName &"','" & TotLaps & "','" & LastDate & "','" & LastTime & "','" & Car & "','" & LapTime & "','" & Track & "','" & Split1 & "','" & Split2 & "','" & Split3 & "','" & Split4 & "','" & Split5 & "','" & Split6 & "','" & Split7 "')")
If AddUser <> True Then
Response.Write("Could not add user information. Operation cancelled.")
Application("dbConnHold")=false ' Release the database table for reading by other pages.
Response.End()
End If
End If
Loop
Else
Response.Write("Cannot access PB.txt or PB.txt is empty. Operation cancelled.")
Application("dbConnHold")=false ' Release the database table for reading by other pages.
Response.End()
End If ' Not TS.AtEndOfStream
TS.Close
Set TS = Nothing
Set objFSO = Nothing
Application("dbConnHold")=false ' Release the database table for reading by other pages.
Response.Redirect(Request.ServerVariables("HTTP_REFERER"))
Function DoSQLCommand(SQLCommand)
Set DoSQL_cmd = Server.CreateObject ("ADODB.Command")
DoSQL_cmd.ActiveConnection = strConnectionString
DoSQL_cmd.CommandText = SQLCommand
DoSQL_cmd.Prepared = true

On Error Resume Next
Set DoSQL = DoSQL_cmd.Execute
DoSQL_numRows = 0

' Handle any errors
If Err.Number <> 0 Then
DoSQLCommand = Err.Number & " - " & Err.Description
Err.Clear
Else
DoSQLCommand = true
End If

DoSQL.Close()
Set DoSQL = Nothing
End Function
%>

[edit] Rather than deleting the database content every time and re-writing it, you could use the following code to create new records and update old ones:

AddUser=DoSQLCommand("INSERT INTO database.Table VALUES('" & RecordID & "','" & Username & "','" & PlyName &"','" & TotLaps & "','" & LastDate & "','" & LastTime & "','" & Car & "','" & LapTime & "','" & Track & "','" & Split1 & "','" & Split2 & "','" & Split3 & "','" & Split4 & "','" & Split5 & "','" & Split6 & "','" & Split7 "') ON DUPLICATE KEY SET PlyName='" & PlyName & "', TotLaps='" & TotLaps & "', LastDate='" & LastDate & "', LastTime='" & LastTime & "', LapTime='" & LapTime & "', Track='" & Track & "', Split1='" & Split1 & "', Split2='" & Split2 & "', Split3='" & Split3 & "', Split4='" & Split4 & "', Split5='" & Split5 & "', Split6='" & Split6 & "', Split7='" & Split7 & "'")

If you do that, you should comment out the lines
DitchContent=DoSQLCommand("DELETE FROM database.Table")
If DitchContent <> True Then
Response.Write("Database connection problem. Operation cancelled.")
Application("dbConnHold")=false ' Release the database table for reading by other pages.
Response.End()
End If

Plus there's less need to hold other pages up if they want to query this table (Application("dbConnHold")).
Attached files
read_lapperPB.zip - 1.5 KB - 162 views
Thanks Sam,

Just got one problem the PSU blew this afternoon on my server and has taken the HD with it. Will test as soon as I get it all up again as off to work now.

Thanks again.

FGED GREDG RDFGDR GSFDG