Page 1 of 1

UI Dialog Question

Posted: Tue Nov 22, 2022 11:05 am
by kcaron
I have some code that uses a for / next loop that takes a list of stock tickers and fetches some data from Bloomberg (MY CURRENT CODE shown below). It works well, but it would be much better if I did not have to open the program and change out the tickers in the body of the code each time the list of stocks changes. It would be very much better to put up a UI box and allow the user to enter in a list of tickers (IBM PG CAT).

My first attempt was to modify some of Gareth's code from the forum (below) and try to substitute %i after "for" in my current code. %i would be the variable that would hold the list of tickers supplied by the user. I assumed the resulting code would insert the user supplied tickers in place of "IBM PG CAT" and run the for next loop as it would when I enter the tickers directly into the code after %i. But this did not happen. Instead, I got an error "Syntax error in control statement in "FOR """ on line XX."

Could someone help me figure out what I've done wrong?

Many thanks!



MY CURRENT CODE:

for %i IBM PG CAT etc...

%name = %i + " US Equity"
fetch(link) bloom::%name 'Historic Price
stocks_price_gp.add {%i}_US
frml {%i}_rtn = ({%i}_US/{%i}_US(-1) - 1) * 100
stocks_rtn_gp.add {%i}_rtn
frml {%i}_excess = {%i}_rtn - tbill_rtn

if @obs({%i}_excess) > 0 then
stocks_excess_gp.add {%i}_excess
endif

next


GARETH'S CODE (Modified by me):

%i = "" 'variable to store list of stocks
!result = 0 ' variable that will track the result of dialogs. -1 indicates user hit Cancel. 0 Indicates user hit OK.
!result = @uiedit(%regs,"Enter the list of stocks") ' put up an Edit dialog asking for regressors list.
if !result=-1 then 'if user cancelled, then stop program
stop
endif

Re: UI Dialog Question

Posted: Tue Nov 22, 2022 11:06 am
by EViews Gareth
What's the line that causes the error?

Re: UI Dialog Question

Posted: Tue Nov 22, 2022 11:11 am
by kcaron
%name = %i + " US Equity"

Re: UI Dialog Question

Posted: Tue Nov 22, 2022 11:21 am
by kcaron
FYI:

I just realized that in my MODIFIED GARETH code, I neglected to change the "%reg" to "%i" in the following line:

!result = @uiedit(%reg,"Enter the list of stocks")
!result = @uiedit(%i,"Enter the list of stocks") <== FIXED

BUT...

I still get the same error, even though I changed "%reg" to "%i"...

Hmmmm?

Re: UI Dialog Question

Posted: Tue Nov 22, 2022 11:23 am
by EViews Gareth
Sorry, I'm struggling to follow what the issue is. Could you post an example that causes the error?

Re: UI Dialog Question

Posted: Tue Nov 22, 2022 11:30 am
by kcaron
Here is a simplified excerpt from the code. When I run it, a UI dialog box opens asking for a list of stocks. I enter "CAT IBM PG", for example, in the UI box. Then, I expect the code to take each ticker that is stored in "%i" from the user supplied input and loop those stocks through the for next loop, fetching prices from Bloomberg. But I am getting this error:

"Syntax error in control statement in "FOR "CAT IBM PG"" on line 65." WHERE LINE 65 is "for %i"


%i = "" 'variable to store list of stocks
!result = 0 ' variable that will track the result of dialogs. -1 indicates user hit Cancel. 0 Indicates user hit OK.
!result = @uiedit(%i,"Enter the list of stocks") ' put up an Edit dialog asking for regressors list.
if !result=-1 then 'if user cancelled, then stop program
stop
endif

for %i

%name = %i + " US Equity"
fetch(link) bloom::%name 'Pull historic prices from Bloomberg
endif

next

Re: UI Dialog Question

Posted: Tue Nov 22, 2022 11:39 am
by EViews Gareth

Code: Select all

%i = "" 'variable to store list of stocks !result = 0 ' variable that will track the result of dialogs. -1 indicates user hit Cancel. 0 Indicates user hit OK. !result = @uiedit(%i,"Enter the list of stocks") ' put up an Edit dialog asking for regressors list. if !result=-1 then 'if user cancelled, then stop program stop endif for %j {%i} %name = %j + " US Equity" fetch(link) bloom::%name 'Pull historic prices from Bloomberg endif next

Re: UI Dialog Question

Posted: Wed Nov 23, 2022 8:58 am
by kcaron
This works great!
Many thanks!

Re: UI Dialog Question

Posted: Mon Dec 05, 2022 9:38 am
by kcaron
Gareth,

Thank you for your help with this UI dialog question from a week ago. It works, but only to a point.

It seems that the UI dialog only accepts a limited number of characters. The list of tickers I need to input is quite long, so most of the list gets truncated when I enter them into the UI dialog.

Is there a workaround for this?

Many thanks!

KC

Re: UI Dialog Question

Posted: Mon Dec 05, 2022 10:40 am
by EViews Gareth