Hi - almost working, if I force the "return" to be a number (4) and I added
IndustryID... to the filter, it works. I started fiddling with StrToNum,
thinking I had to convert, but no luck. Below is the complete code.
1) My csv file is a text file that the numbers 1 through 10 are each in a new
row with no commas.
2) Oddly, printf will display either all the even or all the odd numbers
depending where it is in the code
3) Scan and Explore output data but are not restricted by IndustryID ( that's
why I started to try and use StrToNum)
Thanks greatly
_SECTION_BEGIN("ReadingCSV Function");
Title = "ReadingCSV Function";
id = 0;
Found = "";
item = 0;
function IncludeIndustry( id )
{
local ids;
local fh;
ids = ",";
fh = fopen( "C:\\AmiBroker CSV\\ABTest.csv", "r" );
if ( fh )
{
while ( !feof( fh ) )
{
// printf( fgets( fh ) ); // printf displays only odd numbers ???
ids += fgets( fh );
ids += ",";
printf( fgets( fh ) ); // printf displays only even numbers ???
}
fclose( fh );
}
return StrFind( "," + id + "," , ids ); // original code
/* Found = StrFind( "," + id + "," , ids ); // trying StrToNum ???
Item = StrToNum( "Found" ); // Syntax error ???
Item = StrToNum( "4" ); // this works fine
Item = 4; // forcing return to be 4
return Item;
*/
}
Filter = IndustryID() == IncludeIndustry( IndustryID() );
Buy = Close > 0;
Sell = Close = 0;
AddColumn ( Buy,"Buy" );
AddColumn ( Sell,"Sell" );
AddColumn ( Close,"Close" );
AddTextColumn( FullName(),"FullName" );
AddColumn( id, "Id" );
//AddColumn( Found, "Found" );
AddColumn( Item, "item" );
_SECTION_END();
--- In [email protected], "Mike" <sfclimb...@...> wrote:
>
> Forgot to add the fclose. As always, double check everything given in a forum
> ;)
>
> Mike
>
> --- In [email protected], "Mike" <sfclimbers@> wrote:
> >
> > Ideally, you would use static variables to read the file only once and hang
> > on to the list. That can be your next iteration in the evolution of your
> > code.
> >
> > For now, assuming that the file contains one or more lines of one or more
> > comma separated values (without any blank spaces between values and without
> > blank lines), the path you are following would probably look something like
> > this (untested, going from memory based on an earlier posting by someone
> > else that I can't find right now):
> >
> > function IncludeIndustry(id) {
> > local ids;
> > local fh;
> >
> > ids = ",";
> > fh = fopen("C:\\AmiBroker CSV\\ABTest.csv","r");
> >
> > if (fh) {
> > while(!feof(fh)) {
> > ids += fgets(fh);
> > ids += ",";
> > }
> > }
> >
> > return StrFind("," + id + ",", ids);
> > }
> >
> > Filter = IncludeIndustry(IndustryID());
> >
> > Mike
> >
> > --- In [email protected], "gmorlosky" <gmorlosky@> wrote:
> > >
> > > Ok - here is what I have but can't quite get it to work.
> > > I have the code to fget and the code that I want to replace.
> > > How do I put a loop inside the "New Method" to fget to read the csv file
> > > in place of each "OR" I have in the "Old Method"?
> > >
> > > ****New Method****
> > > _SECTION_BEGIN("ReadingCSV");
> > > Title = "Reading CSV";
> > > fh = fopen("C:\\AmiBroker CSV\\ABTest.csv","r");
> > > if (fh)
> > > {
> > > while(!feof(fh))
> > > {
> > > Numbers = fgets( fh ); // What I need to do is use this list to slim down
> > > the IndustryID to be used
> > > //IndustryID() == Numbers; // This might work, but how to implement ?
> > > }
> > > }
> > > else
> > > {
> > > printf("ERROR: file can not be found (does not exist)");
> > > }
> > > fclose(fh);
> > > _SECTION_END();
> > >
> > >
> > > **** Old method ****
> > > if ( RIDon == 1 ) // RIDon is restrict to these Industrys
> > > Filter = Filter AND (
> > > IndustryID() == 2
> > > OR IndustryID() == 3
> > > OR IndustryID() == 4
> > > OR IndustryID() == 5
> > > OR IndustryID() == 7
> > > OR IndustryID() == 15
> > > );
> > >
> > > > > Does anyone have simple snippet of code that takes a csv file (could
> > > > > be
> > > > > comma delimited or carrage returned) that then can be the input for
> > > > > going
> > > > > through a list.
> > > > >
> > > > > Example: text.csv contains a list of numbers that would be used to
> > > > > "restrict" or "slim down" the IndustryID that is being used for a
> > > > > "display"
> > > > > or "explore".
> > > > >
> > > > > Thanks
> > > > >
> > >
> >
>