Twix mafia Posted January 16, 2014 Share Posted January 16, 2014 Hi im trying to make a script that reads a part of a file and outputting it in a text field. You guys once helped me with reading part of a homepage and outputting it in the Debug in scar - so I tryed to make something like it - but I do not seem to have enough knowledge to rewrite it. This is the file one of you made for me: var client: Integer; procedure ScriptTerminate; begin FreeHTTPClient(client); end; function ExchangeRate(exchange: string): Extended; begin exchange := Trim(exchange); case (exchange <> '') of True: repeat Result := StrToFloatDef(Between('<span id=''last_price''>', '</span>', GetHTTPPage(client, 'http://bitcoinity.org/markets/mtgox/' + exchange)), -1); until (Result > -1); False: Result := -1; end; end; function CalculateCurrencyRate(amount: Extended; fromCurrency, toCurrency: string): Extended; var data: string; tmp: Extended; begin fromCurrency := Trim(fromCurrency); toCurrency := Trim(toCurrency); case ((fromCurrency <> '') and (toCurrency <> '')) of True: repeat data := GetHTTPPage(client, 'http://www.x-rates.com/calculator/?from=' + fromCurrency + '&to=' + toCurrency + '&amount=' + FloatToStr(amount)); Result := StrToFloatDef(Between('<span class="ccOutputRslt">', '<span class="ccOutputTrail">', data), -1); if (Result > -1) then begin tmp := StrToFloatDef(FloatToStr(Result) + Between('<span class="ccOutputTrail">', '</span><span class="ccOutputCode">', data), -1); if (tmp > -1) then Result := tmp; end; data := ''; until (Result > -1); False: Result := -1; end; end; var t: Integer; a, b, c, d, e, f: Extended; begin ClearDebug; client := InitializeHTTPClient(True, True); t := GetSystemTime; a := ExchangeRate('EUR'); b := CalculateCurrencyRate(1, 'EUR', 'USD'); c := (a * b); //Mtgox EUR i USD d := ExchangeRate('USD'); e := (d - c); //difference. Skal være højre end f WriteLn(e); f := ((1/0.994)*(c-(0.994*c))); //Fees. Skal være mindre end e. WriteLn(f); if (e>f) then begin WriteLn('Forskellen er større end fees'); end; if not (e>f) then begin WriteLn('lort'); end; end. I tryed to use the openfile and readfilestring commands (that is described in the WIKI), but i could only output everything or x characters from the start. thats why I tryed to use the "GetHTTPPage" to read my txt file on my harddisk - i THINK it worked, but the script is too advanced for me to rewrite it to something that works all the way. So could I get some help to read part of a file? And how do I make Scar write it? not inside Scar but eg. on a homepage where I have clicked on the writing field? The fact that I don't know the "new" way to output text is one thing - but the big problem is that I dont know how to make scar output the string it just found in a file - As I remember from last time i tryed - I could not make it output a string - so thats part 2 of my question. Quote Link to comment Share on other sites More sharing options...
FHannes Posted January 16, 2014 Share Posted January 16, 2014 If you're storing a dataset in a file for SCAR to work with, it might be more convenient to switch to an SQLite database instead. As for getting a specific part of the file... SCAR does not currently support random access or seeking, so you'll have to read the entire file and parse the data you need from it. Quote Link to comment Share on other sites More sharing options...
Twix mafia Posted January 16, 2014 Author Share Posted January 16, 2014 (edited) Can't I do like with the website, where it reads the data between two unic statements? Like if I have a .txt file (or a .html file) with: *category*Read this*category2**headline*Read this nr. 2*headline2* and then make Scar scan the file and output "Read this" when asked for the text between *category* and *category2*, just like with the website? Because I am having a hard time figuring out exactly how to use SQlite and use it in Scar. Edited January 16, 2014 by Twix mafia Quote Link to comment Share on other sites More sharing options...
FHannes Posted January 16, 2014 Share Posted January 16, 2014 You can, but you'll have to read the file first. Quote Link to comment Share on other sites More sharing options...
Twix mafia Posted January 17, 2014 Author Share Posted January 17, 2014 I somehow can't make anything work - this is my best shot at it: var f: Integer; function Rate(s: string): Extended; begin f := OpenFile('C:\Users\HP\Desktop\' + 'Test.txt', False); ReadFileString(f, s, FileSize(f)); WriteLn('I read this in the file between *cat* and *cat2*: ' + FloatToStr(Rate('*cat*'))); end. Quote Link to comment Share on other sites More sharing options...