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" <gmorlo...@...> 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
> > >
>