April 13, 201312 yr Newbies I'm using the script provided at http://cookingwithplugins.com/recipe.htm?id=125 and it always returns a 1 at the beginning. Any ideas to get rid of this stray 1? SMSetVariable ( "symbol" ; MyTable::stock_symbol ) & EvaluateGroovy ( "String url = "http://download.finance.yahoo.com/d/quotes.csv?s=" + symbol + "&f=l1"; return new URL(url).getText().trim();" )
April 13, 201312 yr Solution That is an error in the recipe. It does what you tell it to do.  Return the (string) result of: SMSetVariable ( "symbol" ; MyTable::stock_symbol )   /* =1 for success I guess */ & /*<- remember this symbol? It concatenates strings */ EvaluateGroovy ( "...  What the author meant is most probably:  SMSetVariable ( "symbol" ; MyTable::stock_symbol ) AND EvaluateGroovy ( "...  which does not work either because it simply returns the "1" which means the ANDed result of both operations (with the desired result of the stock quote being discarded).  So we have to play it a bit safer here and ask explicitly for the success of the SMSetVariable call:   If (  SMSetVariable ( "symbol" ; MyTable::stock_symbol ) ;     EvaluateGroovy ( "String url = "http://download.finance.yahoo.com/d/quotes.csv?s=" + symbol + "&f=l1"; return new URL(url).getText().trim();" );     "")   Or you could make it a ScripMaster module which would look like this:    Remember: ScripMaster returns text. If you live in a region of the world where "," instead of "." is used, you'll have to substitute that yourself.
April 13, 201312 yr Or use the more Groovy form with singe apostrophe inside the function which makes it easier to read in FM If ( SMSetVariable ( "symbol" ; MyTable::stock_symbol ) ; EvaluateGroovy ( "url = 'http://download.finance.yahoo.com/d/quotes.csv?s=' + symbol + '&f=l1'; return new URL(url).getText().trim();" ); "")
April 13, 201312 yr Author Newbies Thank you Karsten and John, your suggestions worked and are appreciated.
Create an account or sign in to comment