Table sizing
The number one weird thing about table objects is that they don't really have a size. You can create a table with 4 rows and 3 columns, and then tell EViews to put something into the 100th row, and EViews will quite happily do it, simply resizing the table on-the-fly to add the 96 extra rows. Even more weird, not only will it add 96 extra rows, but sometimes it will add a few more as padding.
Although this behaviour can be very handy - you don't have to worry about sizing the table upon creation, you can just make it any size and then fill in the cells as you go, it also has a number of drawbacks that you have to work around.
The first is that there is no way to find out how many rows/columns a table currently has. Thus if you want to add something to the end of a table, but don't know where the end is, it can be impossible to do. Thus you have to keep track of exactly how big your table is at all times.
A second, even bigger drawback, is that although a table object will resize itself when you tell it to enter data into a cell that isn't currently in the table, it will not resize itself when you adjust some of the formats of cells. For example, say you have the following code:
Code: Select all
table(3,3) mytab
mytab.setwidth(5) 20
mytab(1,5) = "My Table Header"
This is even more of a problem when you declare a table with no size at all, which is frequently the case:
Code: Select all
table mytab
mytab.setwidth(5) 20
mytab(1,5) = "My Table Header"
However the following code:
Code: Select all
table mytab
mytab(1,5) = "My Table Header"
mytab.setwidth(5) 20
This means that you either have to create your table to be exactly the correct size, or you have to apply all of your formatting at the end of the table creation code.
There are undoubtedly even more quirks that the auto-resizing of tables can cause, so be on the look out!
Use Row/Column counters
I usually fill my tables in row by row, starting at the top. When I do this I use a program variable (usually called !row or !rowcounter) to keep track of which row I am on in the table. This means that rather than having code that looks like this:
Code: Select all
table mytab
mytab(1,1) = "This is my table header"
mytab(2,1) = "This is some time information"
mytab(3,1) = "This is some estimation information"
mytab(4,1) = "This is some forecast information"
Code: Select all
table mytab
!row=1
mytab(!row,1) = "This is my table header"
!row = !row + 1
mytab(!row,1) = "This is some time information"
!row = !row + 1
mytab(!row,1) = "This is some estimation information"
!row = !row + 1
mytab(!row,1) = "This is some forecast information"
!row = !row + 1
Code: Select all
mytab(2,1) = "This is some estimation information"
mytab(3,1) = "This is some forecast information"
Obviously, if you have 40 or so rows in your program this is a huge difference.
Further, if you want to copy and paste some table code from one Add-in program to another, if both programs are using the !row counter method, you can just copy and paste without having to worry about the size different.
Time/Date information
Many EViews output tables show the time/date that the procedure was performed. This can be added easily to your table with the following:
Code: Select all
%datestring = "Date: " + @datestr(@now,"MM/DD/YY") + " Time: " + @datestr(@now,"HH:MI")
mytab(!row,1) = %datestring
One more issue is that a lot of the table commands that take in cells will not let you perform arithmetic inside the command. i.e.:
Code: Select all
mytab.setfont(!row + 1, 3) +b
Code: Select all
!temprow = !row + 1
mytab.setfont(!temprow,3) +b
Code: Select all
mytab(!row + 1, 3) = "hello"
