CategoryFind different results

Please see that both listname and Listname1 are text strings that match yet they are giving different results with categoryfind(). I am sure I am missing something, but I cannot determine what.

Screenshot 2022-09-27 133020

testing="";
fh =fopen("C:\\Program Files\\AmiBroker\\Data\\WatchLists\\index.txt","r");
if( fh ) 
 { 
    while( ! feof( fh ) )
     {
         line = fgets(fh);
         testing = testing+StrExtract(line,0)+",";
    
    }
 } 
else 
 { 
    printf("Error opening file"); 
 } 
fclose(fh);

testing1 = "Dow Jones Industrial Average Current & Past,Dow Jones Industrial Average";
category = categoryWatchlist;
listname = ParamList("Name",testing);
listname1 = ParamList("Name",testing1);
listnum = CategoryFind( listname, category );
listnum1 = CategoryFind( listname1, category );
symbolList = CategoryGetSymbols( categoryWatchlist, listnum ); 

The code as posted does not produce the results that you show. I modified it as shown here, and both listnum and listnum1 refer to the same watchlist.

testing = "Dow Jones Industrial Average Current & Past";
testing1 = "Dow Jones Industrial Average Current & Past";
category = categoryWatchlist;
listname = ParamList("Name",testing);
listname1 = ParamList("Name1",testing1);
listnum = CategoryFind( listname, category );
listnum1 = CategoryFind( listname1, category );
symbolList = CategoryGetSymbols( categoryWatchlist, listnum ); 

What you created was testing and testing1 exactly the same, but if you create testing with the fopen loop and testing1 with equaling string then you get those results i posted.

Pleae try running entire code with fopen loop

You probably have newline characters (\n or \r\n) that need to be stripped off. Have a look at the StrTrim() function.

2 Likes

@mradtke is right.

You need to change your read line to:

    testing = testing + StrTrim( StrExtract( line, 0 ), "\n" ) + ",";

By the way, on my system the watchlist names, using the Amibroker UI to modify them are truncated at 40 chars, so be careful if you create names outside of the application (the first one in your example is longer).

3 Likes

Thank you @mradtke and @beppe.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.