Microsoft KB Archive/45058

From BetaArchive Wiki
Knowledge Base

Explanation of Top% in ToolBoxSampler Example for QuickBASIC

Article ID: 45058

Article Last Modified on 11/21/2006

This article was previously published under Q45058


This article explains how the variable Top% is used in the ToolBoxSampler sample program. Included are details that explain how the program scrolls a window.

ToolBoxSampler is found in the "QB Demos" folder on the disk for Microsoft QuickBASIC for the Apple Macintosh.


The Top% variable is used for two different purposes. The following line determines where to place the window:

   Top% = PEEKW(&HBAA) + (SYSTEM(6)-PEEKW(&HBAA) - 290)\4

PEEK(&HBAA) returns the vertical dimension of the Menu bar. SYSTEM(6) returns the vertical dimension of the screen, so the above code computes a vertical offset that is independent of screen size and starts roughly one-quarter of the way down the screen.

The second use of Top% is part of the "click in scroll box" routine. Its purpose is to determine which line of text was clicked on. The main loop continually calls the ScrollText statement, so that Top% is regularly updated with the actual value of the first line of text currently being displayed in the scroll bar text area. When an item is clicked in the scroll bar text area, the DoMouse routine is called, which includes the following:

   linenum% =(pt%(0) - 6)\21 + Top%

Since the Scroll box rectangle starts at vertical pixel offset 6 [ SetRect src%(0),3,6,114,111 ], the value of pt%(0)-6 is the vertical pixel offset inside the scroll box of the mouse click. The vertical spacing between each of the lines is 21 pixels, so (pt%(0)-6)\21 is the text line offset of the mouse click in the scroll box. Top% contains the offset of the first line of displayed text in the scroll box, so linenum% gets set to the offset into the string that is being displayed in the scroll box.

Note that a backslash (\) is the integer-division operator in BASIC.

Additional query words: MQuickB

Keywords: KB45058