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"
You might think that this would set the width of the 5th column to be 20, and then enter the text "My Table Header" into the top of the 5th column However since the table was created with only 3 columns, the setwidth command is ignored.
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"
This code will behave exactly the same way as the above code - i.e. the setwidth command will be ignored, since a default table does not have 5 columns.
However the following code:
Code: Select all
table mytab
mytab(1,5) = "My Table Header"
mytab.setwidth(5) 20
will work, since the table has automatically added a 5th column before the setwidth command is used.
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"
I have code that looks like this:
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
Clearly this way is a lot more cumbersome. However it has distinct advantages. The first is that I always know how many rows are in my table (!row). Secondly it means that if I decide to remove a row, or change position of a row, all I have to do is remove that line from the program, without changing any of the other lines. For example in the first code segment above, if I wanted to remove the "This is some time information" line, I would then have to change the third and fourth rows so that they now say:
Code: Select all
mytab(2,1) = "This is some estimation information"
mytab(3,1) = "This is some forecast information"
whereas all I have to do in the second segment is remove the line, none of the other lines need be changed at all.
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
Cell arithmetic
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
will error. You'll have to do the arithmetic outside the command:
Code: Select all
!temprow = !row + 1
mytab.setfont(!temprow,3) +b
This doesn't apply to direct cell assignment though - You can do the following:
Code: Select all
mytab(!row + 1, 3) = "hello"