Tutorial 028 Scrollable Adding Machine


If you are adding up a very long list of items, its always useful to be able to go back and check that you haven't missed anything or made a mistake in any of the entries.

The following program makes use of Richard Russell's VSCROLL demonstration program to append a scrollable results table to the simple adding machine program in my demo progs section.

      REM: Adding Machine with scrollable results table
      REM: Richard Weston 28.05.03
      REM: Using Richard Russell's......
      REM. Program to demonstrate the use of a scroll bar in BBC BASIC
      :
      REM. First create a vertical scroll bar:
      SYS "GetWindowLong", @hwnd%, -16 TO ws%
      SYS "SetWindowLong", @hwnd%, -16, ws% OR &200000 : REM. WS_VSCROLL
      MODE 8
      VDU 26 : REM. Adjust windows to take account of scroll bar
      :
      REM: Here's the bit RW added!
      PROCadding
      :
      REM. Initialise global variables:
      Rows% = (@vdu%!36-@vdu%!32)/16 : REM. Number of displayed rows
      Cols% = (@vdu%!28-@vdu%!24)/8  : REM. Number of displayed columns
     
      Vscroll% = 0                   : REM. Initial scroll position
      Minscroll% = 0
      Maxscroll% = Lines%-Rows%
      :
      REM. Strings for scrolling down and up:
      dn$ = CHR$30+CHR$11
      up$ = CHR$31+CHR$0+CHR$(Rows%-1)+CHR$10
      :
      :
      REM. Initialise the scroll bar:
      SYS "SetScrollRange", @hwnd%, 1, Minscroll%, Maxscroll%, 0
      :
      ON MOVE PROCscroll(@msg%,@wparam%) : RETURN
      :
      REM. Display the first 'page':
      FOR line% = 0 TO Rows%-1
        PRINT TAB(0,line%) LEFT$(buffer$(line%),Cols%);
      NEXT
      :
      REM. Scroll as requested:
      vsc% = 0 : REM. Current scroll position
      OFF
      REPEAT
        WHILE (Vscroll% < vsc%) vsc% -= 1 : PRINT dn$ LEFT$(buffer$(vsc%),Cols%); : ENDWHILE
        WHILE (Vscroll% > vsc%) vsc% += 1 : PRINT up$ LEFT$(buffer$(vsc%+Rows%-1),Cols%); : ENDWHILE
      UNTIL INKEY(1)=0
      ;
      REM. Process the scroll commands:
      DEF PROCscroll(msg%,wp%)
      IF msg% <> &115 ENDPROC
      CASE wp% AND &FFFF OF
        WHEN 0: IF Vscroll% > Minscroll% Vscroll% -= 1
        WHEN 1: IF Vscroll% < Maxscroll% Vscroll% += 1
        WHEN 2: IF Vscroll% > (Minscroll%+Rows%) Vscroll% -= Rows% ELSE Vscroll% = Minscroll%
        WHEN 3: IF Vscroll% < (Maxscroll%-Rows%) Vscroll% += Rows% ELSE Vscroll% = Maxscroll%
        WHEN 4,5: Vscroll% = wp% >> 16
      ENDCASE
      SYS "SetScrollPos", @hwnd%, 1, Vscroll%, 1
      ENDPROC
      ;
      DEF PROCadding
      REM Simple Adding Machine
      Lines%=200: REM : max number of entries - alter if you want more
      DIM buffer$(Lines%)
      PRINT"ADDING MACHINE"
      PRINT"Enter a zero to see the scrollable results"'
      PRINT"Press 'Enter' after each entry"TAB(40)"Use a minus sign for subtraction"
      PRINT'TAB(15)"entry"TAB(35)"TOTAL"'
      line%=-1
      total=0
      REPEAT :y=VPOS
        line%+=1
        INPUTTAB(15)entry
        total=total + entry
        PRINTTAB(30,y)total
        IF entry<>0 THEN
          len=LEN(STR$(entry))
          buffer$(line%)="Entry : "+STR$(entry) +" "+ STRING$(20-len,"-") + " total : "+STR$(total)
        ENDIF
      UNTIL entry=0
      CLS
      ENDPROC


Next Tutorial

Richard Weston's Homepage