Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Scrolling Horizontally
#1
Is there any (simple - I'm a Newbie) code that allows me to scroll horizontally. I have a data base that has 100 characters total for the first line. I need to scroll horizontally to view the entire entry. Also, I need to scroll vertically for more than 30 rows.

Please help. Thanks
Reply
#2
I'll assume when you say, "I have a database of 100 characters for the first line." that you've assigned this to a string - lets say FirstLine$. I don't remeber the numbers for tapping the arrow keys off hand, so just use < and > to scroll.

Code:
CLS
Pointer = 1 'As you scroll left/right, pointer will -/+
PRINT LEFT(FirstLine$, 80) ' Prints the initial characters to screen
FirstLine$ = FirstLine$ + STRING$(" ", 100) 'Add a bunch of blank spaces so we won't have to worry about going past the end of FirstString$ later on

Do
If LEN(INKEY$) THEN 'If user presses a key, then...
   If INKEY$ = "." AND Pointer < 100 THEN Pointer = Pointer + 1
   If INKEY$ = "," AND Pointer > 1 then Pointer = Pointer - 1
   CLS
   PRINT MID$(FirstLine$, Pointer, 80) 'Prints 80 characters (the length of the screen) from FirstLine$, starting with Pointer
end if
Loop until INKEY$ = " " 'Press spacebar to quit

Untested.

::EDIT::
Use similar code, but with arrays, to scroll in 2D. This is not very efficent code for large maps, but it's simple, and it (hopefully) works.
Reply
#3
This code scrolls the four directions. It uses a string array as a buffer. Please ask what you don't understand.
Code:
SCREEN 0: WIDTH , 25: CLS
CONST NLINES = 20
CONST NCOLS = 70
CONST FIRSTCOL = 5
CONST FIRSTLINE = 2
'let's create a fake database
OPEN "database.txt" FOR OUTPUT AS #1
FOR I% = 1 TO 100
  PRINT #1, "line" + STR$(I%) + ": ";
  TOT! = 0
  FOR J% = 1 TO RND * 20
    B! = RND * 20 - 10
    TOT! = TOT! + B!
    PRINT #1, USING "+ #####.### "; B!;
  NEXT J%
  PRINT #1, "= "; TOT!
NEXT I%
CLOSE 1

'let's index the start of each record. if your records are of constant length
'this is not needed.

OPEN "database.txt" FOR INPUT AS #1

REDIM index&(200)
I% = 0
WHILE NOT EOF(1)
I% = I% + 1
index&(I%) = SEEK(1)
LINE INPUT #1, A$
WEND
nrecs% = I%

'This is the buffer, an array of constant length strings
DIM SHARED sc(1 TO NLINES) AS STRING * NCOLS


'coordinates in the file of the top left corner of our screen
curx% = 1
cury% = 1

'fill the buffer array for the first time
SEEK #1, index&(cury%)
FOR I% = 1 TO NLINES
LINE INPUT #1, A$
IF curx% <= LEN(A$) THEN LSET sc(I%) = MID$(A$, curx%) ELSE LSET sc(I%) = ""
NEXT I%

LOCATE 24, 1: PRINT "Press ESCAPE to exit"

'displaying loop
DO
  'display it
  FOR I% = 1 TO NLINES
   LOCATE FIRSTLINE + I% - 1, FIRSTCOL
   PRINT sc(I%);
  NEXT

'wait for a key
DO: k$ = INKEY$: LOOP UNTIL LEN(k$)

SELECT CASE RIGHT$(k$, 1)
CASE "K" 'CURSOR LEFT
    
    IF curx% > 1 THEN
      curx% = curx% - 1
      'back to our last first line
      SEEK #1, index&(cury%)
      'fill again all lines starting one position left
      FOR I% = 1 TO NLINES
       LINE INPUT #1, A$
       IF curx% <= LEN(A$) THEN LSET sc(I%) = MID$(A$, curx%) ELSE LSET sc(I%) = ""
      NEXT I%
    END IF
CASE "M" 'CURSOR RIGHT
    IF curx% < 300 THEN
      curx% = curx% + 1
      'back to our last first line
      SEEK #1, index&(cury%)
      'fill again all lines starting one position right
      FOR I% = 1 TO NLINES
       LINE INPUT #1, A$
       IF curx% <= LEN(A$) THEN LSET sc(I%) = MID$(A$, curx%) ELSE LSET sc(I%) = ""
      NEXT I%
    END IF

CASE "H" 'CURSOR UP
   IF cury% > 1 THEN
     cury% = cury% - 1
     'move up what we have in the buffer
     FOR I% = NLINES TO 2 STEP -1
       LSET sc(I%) = sc(I% - 1)
     NEXT
     'fill bottom line
     SEEK #1, index&(cury%)
     LINE INPUT #1, A$
     IF curx% <= LEN(A$) THEN LSET sc(1) = MID$(A$, curx%) ELSE LSET sc(1) = ""
   END IF

CASE "P" 'CURSOR DOWN
   IF cury% < nrecs% - NLINES - 1 THEN
     cury% = cury% + 1
     'move down what we have in the buffer
     FOR I% = 1 TO NLINES - 1
       LSET sc(I%) = sc(I% + 1)
     NEXT
     'fill thefirst line
     SEEK #1, index&(cury% + NLINES + 1)
     LINE INPUT #1, A$
     IF curx% <= LEN(A$) THEN LSET sc(NLINES) = MID$(A$, curx%) ELSE LSET sc(NLINES) = ""
   END IF
END SELECT
LOOP UNTIL k$ = CHR$(27)
Antoni
Reply
#4
LOL. The "100 characters" bit made me think this was for an RPG scrolling map or something. Sorry 'bout that ed. :wink:
Reply
#5
Thanks All for your help.

I'm using a powerbasic 3.5 compiler.

When I tried to run Antoni's code, an error message came up that stated "variable expected" at this line:

DIM SHARED sc( 1 to NLINES) AS STRING * NCOLS

Also, What does the "sc" represent?

I went to the qbasic help section of this forum, but could not correct the situations above. Please help.
Thanks.
Reply
#6
"sc" is "string columns"
am an asshole. Get used to it.
Reply
#7
Try removing "CONST". Maybe PB doesn't like it. PB is not 100% QB compatible. But I am not pretty sure, I don't have the compiler to test it.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#8
I have only tried PB 3.5, so I don´t know all of it's tricks.
I think PB 3.5 has only integer constants, they are defined with the keyword EQV (or something like this, maybe EQV%).

As Nathan said, my code will work exactly the same if you remove the keyword CONST in the program.

For PB-related issues you may find a better help here http://www.powerbasic.com/support/forums/Ultimate.cgi
Antoni
Reply
#9
I removed Const from the code and made a few other minor changes and the code worked.

I'll learn from this code to make my program work better.

Thanks for your help.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)