Access table cells with variables

For questions regarding programming in the EViews programming language.

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

cap
Posts: 55
Joined: Fri Oct 17, 2008 11:47 am

Access table cells with variables

Postby cap » Mon Nov 24, 2008 10:08 am

Hello,

I would like to access certain cells inside a table using variable indices. For example, to print numbers down the 2nd column, I thought this would work:

______________________
table mytable

for !i=1 to !i=5
regout(2,!i)=!i
next

______________________


But, this did not work, and after running the program I get no error messages...


Thanks in advance,
-cap

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

Re: Access table cells with variables

Postby EViews Gareth » Mon Nov 24, 2008 10:13 am

What's regout?
Follow us on Twitter @IHSEViews

cap
Posts: 55
Joined: Fri Oct 17, 2008 11:47 am

Re: Access table cells with variables

Postby cap » Mon Nov 24, 2008 11:40 am

Sorry, its just the name of the same table, I meant to edit my code as follows:


______________________
table mytable

for !i=1 to !i=5
mytable(2,!i)=!i
next

______________________

Any help would still be appreciated, thanks,
-cap

cap
Posts: 55
Joined: Fri Oct 17, 2008 11:47 am

Re: Access table cells with variables

Postby cap » Mon Nov 24, 2008 12:07 pm

Ok, it seems now that the code does actually work, but now I can not use the loop variable in computations. For example, when I assign a cell the value !i+10, it still only puts in the value !i.

___________________________
table mytable

for !i=1 to !i=5
mytable(1,!i)=!i+10
next

___________________________


Any ideas?

-cap

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

Re: Access table cells with variables

Postby EViews Gareth » Mon Nov 24, 2008 2:14 pm

You have the syntax of the for loop incorrect.

Your code should be:

Code: Select all

for !i=1 to 5
mytable(1,!i)=!i+10
next
Follow us on Twitter @IHSEViews

cap
Posts: 55
Joined: Fri Oct 17, 2008 11:47 am

Re: Access table cells with variables

Postby cap » Mon Nov 24, 2008 2:41 pm

Ah, sorry, dumb question, thanks very much though.

-cap


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 27 guests