UI Dialog Question

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

kcaron
Posts: 92
Joined: Wed Mar 04, 2015 11:46 am

UI Dialog Question

Postby kcaron » Tue Nov 22, 2022 11:05 am

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

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13401
Joined: Tue Sep 16, 2008 5:38 pm

Re: UI Dialog Question

Postby EViews Gareth » Tue Nov 22, 2022 11:06 am

What's the line that causes the error?
Follow us on Twitter @IHSEViews

kcaron
Posts: 92
Joined: Wed Mar 04, 2015 11:46 am

Re: UI Dialog Question

Postby kcaron » Tue Nov 22, 2022 11:11 am

%name = %i + " US Equity"

kcaron
Posts: 92
Joined: Wed Mar 04, 2015 11:46 am

Re: UI Dialog Question

Postby kcaron » Tue Nov 22, 2022 11:21 am

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?

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13401
Joined: Tue Sep 16, 2008 5:38 pm

Re: UI Dialog Question

Postby EViews Gareth » Tue Nov 22, 2022 11:23 am

Sorry, I'm struggling to follow what the issue is. Could you post an example that causes the error?
Follow us on Twitter @IHSEViews

kcaron
Posts: 92
Joined: Wed Mar 04, 2015 11:46 am

Re: UI Dialog Question

Postby kcaron » Tue Nov 22, 2022 11:30 am

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

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13401
Joined: Tue Sep 16, 2008 5:38 pm

Re: UI Dialog Question

Postby EViews Gareth » Tue Nov 22, 2022 11:39 am

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
Follow us on Twitter @IHSEViews

kcaron
Posts: 92
Joined: Wed Mar 04, 2015 11:46 am

Re: UI Dialog Question

Postby kcaron » Wed Nov 23, 2022 8:58 am

This works great!
Many thanks!

kcaron
Posts: 92
Joined: Wed Mar 04, 2015 11:46 am

Re: UI Dialog Question

Postby kcaron » Mon Dec 05, 2022 9:38 am

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

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13401
Joined: Tue Sep 16, 2008 5:38 pm

Re: UI Dialog Question

Postby EViews Gareth » Mon Dec 05, 2022 10:40 am

Follow us on Twitter @IHSEViews


Return to “Programming”

Who is online

Users browsing this forum: Bing [Bot] and 2 guests