I'm writing a converter because the ones I've found don't do
quite what I'd like them to do. Here is what I have so far.
It is functional but needs a lot of work.
Any suggestions are appreciated.
Thank You.
Joe B.
p.s. use as you wish...
Code: Select all
;-------------------------------------------------------------------------
; A simple CSV to HTML file converter
; works O.K., but has a bug with
;"empty" data at the end of a line (e.g.: 3,test,)
; I hope to add coloring....
; any help appreciated!
;-------------------------------------------------------------------------
text$ = "by the elecTRONics DOCtor" ; just a small text$ string
dlay2 = 2000 ; delay will set to 4000
OpenConsole()
ConsoleTitle ("TronDoc's CSV2HTML")
If ReadFile(0, "InPut.CSV")
If OpenFile(1, "OutPut.html")
WriteStringN("")
CloseFile(1)
Else
ClearConsole()
CloseConsole()
MessageRequester("PureBasic", "Error: Can't read the file", 0)
End
EndIf
While Eof(0)=0
CSV$ = StripTrail(StripLead(ReadString()))
PrintN ("Working...")
Gosub CSV2HTML
UseFile(0)
Wend
CloseFile(0)
Else
MessageRequester("PureBasic", "Error: Can't read the file", 0)
EndIf
If OpenFile(1, "OutPut.html")
Length = Lof()
FileSeek(Length)
WriteStringN("")
CloseFile(1)
Else
ClearConsole()
CloseConsole()
MessageRequester("PureBasic", "Error: Can't read the file", 0)
End
EndIf
PrintN("DONE!")
Delay(dlay2) ; Waits for moment
;-------- Cls --------
ClearConsole() ; This will clean the ConsoleScreen
CloseConsole()
End
CSV2HTML:
NewString$=""
CSVlen = Len(CSV$)
PrintN(Str(CSVlen))
commaCount = 0
PrevChar$=""
For StartPosition = 1 To CSVlen
CSVchar$ = Mid(CSV$, StartPosition, 1)
If CSVchar$","
ADDchar$ = CSVchar$
Else
If PrevChar$ = "," Or StartPosition = 1 Or StartPosition = CSVlen
Addchar$ = "Â "
Else
AddChar$ = ""
EndIf
EndIf
PrevChar$ = CSVchar$
NewString$ = NewString$ + ADDchar$
Next StartPosition
NewString$=NewString$+""
Gosub WriteHTML
Return
WriteHTML:
If OpenFile(1, "OutPut.html")
Length = Lof()
FileSeek(Length)
WriteStringN(NewString$)
CloseFile(1)
EndIf
Return
;REM SAMPLE INPUT FILE:
;REM ------------InPut.CSV----------------
;REM DATE,TANDEM,W/VIDEO,,S/L,W/VIDEO,
;REM 2001.05.12,5,2,,20,1
;REM ,3,,4,1
;REM ,,,,,,
;REM 2001.05.13,0,0,0,0,,
;REM 2001.05.19,10,5,15,3,4
;REM --------------------------------------
Edited by - TronDoc on 25 April 2002 06:10:41
