metro
Full Member
Posts: 180
|
Post by metro on Sept 13, 2015 5:05:47 GMT -5
Despite my best efforts I'm struggling to solve this any help appreciated I've been trying to create links in a table and have found this to be useful www.runbasic.com/docs/tables.htmlI need to create a 2 dimentional array from a csv file The first field " FMGJI7" (on each line) needs to be tabledata$(0,x) (stating the obvious for most of you) line$(0)="FMGJ17;24/09/2015;Call;1.000;1.030;1.030;0.000;0;0;0;1.0" line$(1)="FMGJ27;24/09/2015;Put;1.000;0.000;0.000;0.000;0;0;0;0.0" line$(2)= "FMGJ47;24/09/2015;Call;1.100;0.930;0.930;0.000;0;0;0;0.9" this is all I have DIM tabledata$(100,11): dim token$(11) for a = 0 to 2 for idx=1 to 10 token$(idx) = word$(line$(a), idx, ";") print token$(idx) next idx next a thanks in advance EDIT: A little closer, not sure how to get the array to start from zero when using word$ if in fact it needs to be from zero for column =1 to 11 for a=0 to 2 item$ =word$( line$(a), column, ";") tabledat$(column, a) =item$ print tabledat$(column,a) next a next column
|
|
|
Post by meerkat on Sept 13, 2015 9:07:27 GMT -5
Hello down under.. Took a look and it all depends on how you look at it. Your code appears ok if that's they way you want it loaded into the dims() I rearranged your code a little and loaded it the way I understand it.
Have a great day mate.
dim line$(100) line$(0)="FMGJ17;24/09/2015;Call;1.000;1.030;1.030;0.000;0;0;0;1.0" line$(1)="FMGJ27;24/09/2015;Put;1.000;0.000;0.000;0.000;0;0;0;0.0" line$(2)= "FMGJ47;24/09/2015;Call;1.100;0.930;0.930;0.000;0;0;0;0.9"
DIM tabledat$(100,11): dim token$(11)
for lne = 1 to 3 for col = 0 to 10 item$ = word$( line$(lne-1), col+1, ";") tabledat$(lne, col) = item$ print tabledat$(lne,col);" ";lne;" ";col;" ";chr$(9); next col print next lne
|
|
metro
Full Member
Posts: 180
|
Post by metro on Sept 13, 2015 9:49:27 GMT -5
G'day Dan
I eventually solved the problem, it seems the table array has to be zero based or the "link's" will not function correctly the saved data below will get cleaned up in the final draft as the first 4 lines are not needed but are taken care of at the moment with the code below.
I have a functioning program running in LB4 and have decided to take advantage of RB, SQLite and tables
save this as myCsv.csv
"Code;andnbsp;Last;$ +/-;Bid;Offer;Open;High;Low;Volume;Options;Warrants andamp; Structured Products;CFDs;Chart;Stat "FMG;2.030andnbsp;;-0.010;2.020;2.040;2.100;2.110;2.020;12,513,696;Options;Warrants andamp; Structured Products;CFDs;;
"Code;Expirydate;P/C;Exercise;Bid;Offer;Last;Volume;Openinterest;Margin Pri " FMGW48;24/09/2015;Call;0.010;2.020;2.020;0.000;andnbsp;;11,429;2.0 " FMGJ17;24/09/2015;Call;1.000;1.030;1.030;0.000;andnbsp;;0;1.0 " FMGJ27;24/09/2015;Put;1.000;0.000;0.000;0.000;andnbsp;;0;0.0 " FMGJ47;24/09/2015;Call;1.100;0.930;0.930;0.000;andnbsp;;0;0.9 " FMGJ37;24/09/2015;Put;1.100;0.000;0.000;0.000;andnbsp;;0;0.0 " FMGJ57;24/09/2015;Call;1.200;0.830;0.830;0.000;andnbsp;;0;0.8 " FMGJ67;24/09/2015;Put;1.200;0.000;0.000;0.000;andnbsp;;0;0.0 " FMGJS7;24/09/2015;Call;1.300;0.730;0.730;0.000;andnbsp;;0;0.7 " FMGJP7;24/09/2015;Put;1.300;0.000;0.000;0.000;andnbsp;;2,100;0.0 " FMGX47;24/09/2015;Call;1.350;0.685;0.685;0.000;andnbsp;;0;0.6 " FMGX57;24/09/2015;Put;1.350;0.000;0.000;0.000;andnbsp;;100;0.0 " FMGJT7;24/09/2015;Call;1.400;0.635;0.635;0.000;andnbsp;;100;0.6 " FMGJU7;24/09/2015;Put;1.400;0.000;0.000;0.000;andnbsp;;1,000;0.0 " FMGL67;24/09/2015;Call;1.450;0.585;0.585;0.000;andnbsp;;0;0.5 " FMGL77;24/09/2015;Put;1.450;0.000;0.000;0.000;andnbsp;;1,600;0.0 " FMGIG7;24/09/2015;Call;1.500;0.535;0.535;0.000;andnbsp;;0;0.5 " FMGIH7;24/09/2015;Put;1.500;0.001;0.001;0.000;andnbsp;;7,170;0.0
' ------------------------------------- ' HTML <table> data to CSC file ' converts all tables in the html ' change: webPage$ and fileName$ belohtml " w ' Credit to Dan Kokenge ' -------------------------------------- sep$=Chr$(34)+Chr$(44)+Chr$(34) DIM a$(1000):dim dat$(1000): DIM tabledat$(11,1500) Dim row$(1000)
' change this to your output csv file name fileName$ = "myCsv"
Call setCSS
div Container 'Main html "<head>" html "<h1> OPTIONS TRACKING</h1>" html "</head>" html "<div align='right'>" end div
div navigation print "Menu" link #testIt, "Enter New trade", [linkAction] print link #CurPos, "Current Pos", [linkAction] print link #HistData , "Historical", [linkAction] print link #DldIndex, "Download Index", [linkAction] print link #Bacitup, "Backup", [linkAction] end div
goto [loadupdata]
[loadupdata]
open DefaultDir$ + "/public/";fileName$;".csv" for input as #f
a=1 while not(eof(#f)) line input #f, row$ row$=strRep$(row$,"andnbsp","0") row$=strRep$(row$,Chr$(34),"") row$=strRep$(row$,";;",";0;") row$(a)=row$ a=a+1 wend ' SORTED THE ZERO BASE for tabledat$(x,x) ' so the link's would work for column =1 to 11 for a=5 to 20 item$ =word$(row$(a), column, ";") tabledat$(column-1, a-5) =item$ next a next column ' TABLE HEADER
div mytable table #mytable,tabledat$() html "<table border=1>"
#mytable columnnames("Code,Expirydate,P/C,Exercise,Bid,Offer,Last,Volume,Openinterest,MarginPrice") #mytable link("Code", "[order]") #mytable caption("POTENTIAL TRADES") cssclass "table", "{ border: 3px ridge #DDF ; border-spacing: 4px }" html "</table>" render #mytable
end div
div footer html "© Metropolis 2015" end div
wait [order] print "No Order Yet" wait [Opt2Find] ' call alert "Not Coded Yet" print "not coded Opt2Find" wait
[linkAction] print "not coded yet" 'call alert "Not Coded Yet" wait
' sub alert message$ ' html "<script type='text/javascript'> ' function disp_alert() { ' alert('Attention!' + '\n' + '";message$;"'); ' } ' </script>" ' html "<script type='text/javascript'> disp_alert() </script>" ' end sub
' ---------------------------------.-------- ' strip junk ' ----------------------------------------- FUNCTION strip$(str$) strip$ = "" for i = 1 to len(str$) a$ = MID$(str$,i,1) a = ASC(a$) if a > 31 then if a < 127 then if a$ <> "'" then if a$ <> """" then strip$ = strip$ + a$ end if end if end if end if next i END FUNCTION ' -------------------------------- ' string replace rep str with ' -------------------------------- FUNCTION strRep$(str$,rep$,with$) ln = len(rep$) ln1 = ln - 1 i = 1 while i <= len(str$) if mid$(str$,i,ln) = rep$ then strRep$ = strRep$ + with$ i = i + ln1 else strRep$ = strRep$ + mid$(str$,i,1) end if i = i + 1 WEND END FUNCTION ' -------------------------------- ' Replace HTML <tags> with$ ' -------------------------------- FUNCTION tags$(tag$,with$) i = instr(tag$,"<") j = instr(tag$,">",i) WHILE j > i tag$ = left$(tag$,i - 1) + mid$(tag$,j + 1) i = instr(tag$,"<") j = instr(tag$,">") WEND tags$ = tag$ END FUNCTION
Sub setCSS CSSID #Container, "{ align center margin-left: auto; margin-right: auto; width: 70%; Margin: 20px Auto; Background-Color: #C6C6B8; Font-Family: Tahoma; Font-Size: 1em; Font-Weight: Bold; Text-Align: Center; Color: Black; Width: 1000px; Height: 710px; Padding: 20px 20px 0px 10px; Border-Color: #45453D; Border-Size: Thick; Border-Style: Ridge; Border-Bottom-Style: Ridge; }" cssid #navigation, "{ font-family: Tahoma; font-size: small; color: #CC0000; border-right: 3px solid #666666; background: #ADAD99; padding: 4px; width: 250px; height: 570px; float: left; white-space: normal; background-repeat: repeat; background-image: url('/pagebg.PNG'); Text-Align: Center; }" '********************************************************
CSSID #footer, "{ Background-Color:#77776E; Font-Family: Verdana; Width: 999px; Height: 25px; Padding: 5px 5px 5px 0px; Text-Align: Center; }"
CSSID #mytable, "{ Font-Family: Verdana; Font-Size: .75em; Padding: 10px 10px 0px 0px; Width: 675px; Height: 570px; Background-Color: #FFFFFF; overflow-y: scroll; }"
CSSID #h1, "{ font-family: Tahoma; display: block; font-family: Tahoma; color: #3D3D1F; font-size: 2em; margin-top: 0.67em; margin-bottom: 0.67em; margin-left: 0; margin-right: 0; font-weight: bold; }" End Sub
any chance some one can see why the CCID for #mytable has no effect
|
|
|
Post by meerkat on Sept 14, 2015 7:06:51 GMT -5
G'day metro I know you probably have your reasons. But I was curious why you don't place the data in a SQLite DB. Seems like it'd be a lot easier to maintain. And it would give you lots of select options for compares, averages, min/max, and math functions. Just curious!!
sqliteconnect #mem, ":memory:" mem$ = "CREATE TABLE trade ( ticker varchar(10), tradeDate date, placeCall varchar(5), exercise decimal(10,3), bid decimal(10,3), offer decimal(10,3), last decimal(10,3), volume int(10), openInterest int(10), marginPrice decimal(10,3) );" #mem execute(mem$)
a$ = httpget$("http://www.asx.com.au/asx/markets/optionPrices.do?by=underlyingCode&underlyingCode=FMG")
i = instr(a$,"<!-- TODO: MY fix zero & null -->") a$ = mid$(a$,i) a$ = word$(a$,1,"</tbody></table>") i = 1 a1$ = word$(a$,1,"</tr>")
while a1$ <> "" a1$ = strip$(a1$) a1$ = strRep$(a1$,"<td>","','") a1$ = tags$(a1$,"") a1$ = strRep$(a1$," ","") mem$ = "INSERT INTO trade VALUES('";a1$;"')" if a1$ <> "" then #mem execute(mem$) i = i + 1 a1$ = word$(a$,i,"</tr>") wend
' -- do stuff with the DB --- mem$ = "SELECT * FROM trade" #mem execute(mem$) WHILE #mem hasanswer() #row = #mem #nextrow() ticker$ = #row ticker$() exercise = #row exercise() print ticker$;chr$(9);exercise WEND wait
' -------------------------------- ' string replace rep str with ' -------------------------------- FUNCTION strRep$(str$,rep$,with$) ln = len(rep$) ln1 = ln - 1 i = 1 while i <= len(str$) if mid$(str$,i,ln) = rep$ then strRep$ = strRep$ + with$ i = i + ln1 else strRep$ = strRep$ + mid$(str$,i,1) end if i = i + 1 WEND END FUNCTION ' -------------------------------- ' Replace HTML <tags> with$ ' -------------------------------- FUNCTION tags$(tag$,with$) i = instr(tag$,"<") j = instr(tag$,">",i) WHILE j > i ln = (j - i) + 1 x$ = mid$(tag$,i,ln) tag$ = strRep$(tag$,x$,with$) i = instr(tag$,"<") j = instr(tag$,">",i) WEND tags$ = tag$ END FUNCTION
|
|
metro
Full Member
Posts: 180
|
Post by metro on Sept 14, 2015 10:05:17 GMT -5
I'm heading down that path Dan, however I seem to waste a lot of time finding solutions to simple problems. Seems a d**n sight easier with Liberty Basic.
Now I need to see why the strip$ function I've added to your code times out your RB code
|
|
|
Post by meerkat on Sept 14, 2015 10:26:18 GMT -5
Hmmmmm! Never had that happen before.. If you find out why, let me know.. I'll have a look at it..
BRW - the memory SQLite code above loads correctly. And it turns out I didn't need the strip$() function.
If you make it into a DISK SQLite table and use RBgen it will write 90% of the code for you...
Good luck.. If it's past 5PM there, I'll hoist a brew for you....
Dan
|
|