[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] Re: How to sort lines in a file



PureBytes Links

Trading Reference Links

Title: Re: [amibroker] Re: How to sort lines in a file

Thanks again Mike, yes i have it working. See below, however:


1) It would be nice to transform this into a function? I tried but got different types of errors. If i have to i can use an Include file...

2) I can't seem to define variables outside the script, like the file path and name.


Anyone know how to polish this for easier use? perhaps a function with FilePath and Filename arguments?


TIA,

herman



EnableScript( "_vbscript_" );

<%

FilePath = "C:\Program Files\AmiBroker\Test\"

FileToSort="TestReport.csv"

Const adVarChar = 200

Const MaxCharacters = 255

Const ForReading = 1

Const ForWriting = 2


Set DataList = CreateObject("ADOR.Recordset")

DataList.Fields.Append "TempRecordSet", adVarChar, MaxCharacters

DataList.Open


Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.OpenTextFile( FilePath + FileToSort, ForReading)


do Until objFile.AtEndOfStream

strLine = objFile.ReadLine

DataList.AddNew

DataList("TempRecordSet") = strLine

DataList.Update

Loop


objFile.Close

DataList.Sort = "TempRecordSet"

DataList.MoveFirst


do Until DataList.EOF

strText = strText & DataList.Fields.Item( "TempRecordSet" ) & vbCrLf

DataList.MoveNext

Loop


Set objFile = objFSO.OpenTextFile( FilePath + "TestReport.csv", ForWriting )

objFile.WriteLine strText

objFile.Close

%>



Friday, August 22, 2008, 8:46:00 PM, you wrote:


> Herman,


> If you find that it works out for you in the simple case, you can add 

> additional fields to the in memory record structure, parse your line 

> of data into the separate fields, then use any of those fields as the 

> field to sort on. You can then define a variable in AFL for which 

> column you want to sort with and reference that variable within the 

> _vbscript_.


> Modifying the script given, it might look something like this:


> // SortColumn declared in AFL as a String

> SortColumn = "Symbol"; // Must match one of DataList.Fields


> <%

> ...

> Set DataList = CreateObject("ADOR.Recordset")

> DataList.Fields.Append "Symbol", adVarChar, MaxCharacters

> DataList.Fields.Append "Open", adVarChar, MaxCharacters

> DataList.Fields.Append "High", adVarChar, MaxCharacters

> ...

> DataList.Open

> ...

> Do Until objFile.AtEndOfStream

> strLine = Split(objFile.ReadLine, ",")

> DataList.AddNew

> DataList("Symbol") = strLine(0)

> DataList("Open") = strLine(1)

> DataList("High") = strLine(2)

> ...

> DataList.Update

> Loop

> ...

> DataList.Sort = AFL("SortColumn")

> ...



> Again, I haven't actually tried any of this. But, it looks like it 

> should work.


> Mike









> ------------------------------------


> Please note that this group is for discussion between users only.


> To get support from AmiBroker please send an e-mail directly to 

> SUPPORT {at} amibroker.com


> For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:

> http://www.amibroker.com/devlog/


> For other support material please check also:

> http://www.amibroker.com/support.html

> Yahoo! Groups Links


> <*> To visit your group on the web, go to:

>     http://groups.yahoo.com/group/amibroker/


> <*> Your email settings:

>     Individual Email | Traditional


> <*> To change settings online go to:

>     http://groups.yahoo.com/group/amibroker/join

>     (Yahoo! ID required)


> <*> To change settings via email:

>     mailto:amibroker-digest@xxxxxxxxxxxxxxx 

>     mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx


> <*> To unsubscribe from this group, send an email to:

>     amibroker-unsubscribe@xxxxxxxxxxxxxxx


> <*> Your use of Yahoo! Groups is subject to:

>     http://docs.yahoo.com/info/terms/



__._,_.___

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html




Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___