So far we’ve seen examples of passing numbers, strings, and Python objects back and forth between Python and VB. Now we’ll develop some more kinds of views and look at passing around arrays of data at a time. This is a real time saver and can simplify the preceding code in several places.
Many financial reports take the form of a 2D grid or spreadsheet.
What’s needed is a generic solution for getting a Python list
of lists into such a grid. In the last chapter we showed a number of
BookSet methods for getting a list of accounts,
the details of an account and so on. For example,
getAccountDetails returns a list of tuples of
runningTotal). This is
effectively a matrix with five columns but an unknown number of rows.
You need to expose this the usual way in
COMBookSet, but then access the entire matrix from
VB. The Python COM framework automatically converts lists (or lists
of lists, or lists of tuples) into arrays that can be accessed in VB.
We’ve created a new form,
which can be given the name of an account as a string. This has a
Microsoft FlexGrid control called
UpdateView method that fetches
and displays the data:
Public Sub UpdateView() Dim table As Variant Dim rows As Integer, cols As Integer Dim row As Integer, col As Integer table = frmMain.BookServer.getAccountDetails(AccountName) rows = UBound(table, 1) - LBound(table, 1) + 1 cols = UBound(table, 2) - LBound(table, ...