|
|
Tech Note 25b: Using TablesMay 01, 2008Copyright 2008 NS BASIC Corporation |
|
In this document, I will introduce how to display a table nicely, without using the Grid object. Tables are used quite often in applications for many kinds. In a word processor, for example, you may draw lines to create table for organizing data on the screen. That is, a table is a collection of cells, which is arranged in both horizontal and vertical directions. You can draw lines to create a table but the table doesn't let you select or scroll cells. The method I will explain here is to draw lines on the screen while letting users to get data from the table.
Look at the screen below. This application, made using NS Basic, is able to scroll the cells vertically and select data. The program works as follows:
Type SheetData
sWhen as String 'when
sWhat as String 'what
sHow as Integer 'how much
End Type
Global ShDat(30) as SheetData 'array for display
The difference between VB and NS Basic is the place of braces "()".
In NS Basic:
ShDat.sWhat(i)
In Visual BASIC:
ShDat(i).sWhat
Now, we put dummy data in the variable. The date field contains just a number "day" because I assume that "year" and "month" would be displayed somewhere else. The data here doesn't mean anything.
Sub Project_Startup()
Type SheetData
sWhen as String 'when
sWhat as String 'what
sHow as Integer 'how much
End Type
Global ShDat(30) as SheetData 'array for display
'make dummy data here
Dim i as Integer
For i=1 to 25
ShDat.sWhen(i) = Trim(Str(Int(i/3)+1))
ShDat.sWhat(i) = "Data" + str(Int(i/3))
ShDat.sHow(i) = 100*Rand()*100
Next
End Sub
Actually, even though there are 30 elements in the array, there are 25 records. Now, we display the data on the bitmap. The idea is like this: The important point is which record comes to the top of the table. If we find it, we can display 8 records from that record. So we need a variable to keep track of the record.
Global iTop as Integer 'top record data
'initialization
iTop=1
The initial value for the variable is 1.
Dim iSt as Integer
Dim iEd as Integer
DrawBitmap 1004,0,16
iSt=iTop
iEd=iTop+7
For j=iSt to iEd
jy= (j-iSt) * 14 + 31
.....
Next
You have to consider the following things:
You have probably understood the outline of the table creation. Please check the source code for details. You can download the project file here. As you know from the sample, the process is quite fast, so you don't need to use a character object such as Label, drawing characters by DrawChars are very practical. Although non-object program seems old-fashioned, in some case,
it may be better to use graphics window than using objects.
|