Ooops
November 28, 2020, 03:05:49 AM

Author Topic: [bb] Load and Display Text using types B3D (b+ need modification) by Dan [ 1+ years ago ]  (Read 479 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : Load and Display Text using types B3D (b+ need modification)
Author : Dan
Posted : 1+ years ago

Description : This Loads an Text into a type, then displays it in pagelike maner.
Doesnt have any error checking for the loaded file.
Its for B3D as b+ doesnt have locate command, and print goes into console window.
It could be easily adapted for b+ too.


Code :
Code: BlitzBasic
  1. ; Reads an File into Type
  2. ; And displays it on screen
  3. ; Use Arrow keys Up and Down to Browse the text
  4. ; Use Arrow keys Left and right to increase/decrease amount of displayed text
  5. ; Esc to end
  6.  
  7. Type Line       ;Type named line for lines in a file
  8. Field number    ;Has number of lines
  9. Field Text$     ;and the text on that line
  10. End Type
  11.  
  12. Graphics 800,600,0,2     ; 800x600 screen, windowed
  13. SetBuffer = BackBuffer
  14.  
  15. Global newtime,x,y,a
  16.  
  17. filename$ = "textdisplay.bb"           ; Filename to read
  18.  
  19. Txt = ReadFile ( filename$ )    ; Open a file to read
  20.  
  21. a=0
  22. oldtime=MilliSecs()             ; Set timer
  23.  
  24. While Not Eof(txt)              ; Start of reading the file
  25. a=a+1                           ; Line numbers counter
  26. thisLine.Line = New Line        ; New Type named ThisLine
  27. thisline
  28. umber =a              ; Holds the actual line number for later reference
  29. thislineText$= ReadLine$ (txt) ; And reads the Text
  30. Wend
  31. newtime=(MilliSecs()-oldtime)   ; Calculate the speed of reading
  32. CloseFile txt                   ; Closes the filehandle
  33.  
  34.  
  35. x=1              ; Starting point of the Text (1st line)
  36. y=10             ; Display counter (10 lines here)
  37.  
  38.  
  39. ; Main Loop
  40.     Repeat
  41.        ShowLines(x,y)
  42.        
  43.        Delay 20      ; Saves CPU Usage if you care about it !  
  44.        
  45.        key= GetKey()               ; Check for a keypress
  46.        
  47.        Select key
  48.            
  49.             Case 31                ; Arrow Right
  50.               y=y-1
  51.               If y<1 Then y=1
  52.             Case 30                ; Arrow Left
  53.               y=y+1
  54.               If y>44 Then y=44    ; Max of lines to be displayed
  55.             Case 29                ; Arrow Down
  56.                x=x+y
  57.                If (x)>a Then x=x-y
  58.             Case 28                ; Arrow up
  59.                x=x-y
  60.                If x-y<0 Then x=1
  61.        End Select
  62.    
  63.     Flip
  64.    
  65.     Until KeyHit(1)          ; Esc ends
  66.  
  67. ;End of Main Loop
  68.  
  69. End                          ; Game Over :)
  70.  
  71. Function Border()
  72.     Color 255,255,255
  73.    
  74.     Rect 0,0,800,15,1
  75.     Rect 0,585,800,600
  76.    
  77.     Locate 0,585
  78.     Color 255,0,0
  79.     Print "Use Arrows: Up/Down to browse - Left/Right to Dec/Inc lines - Esc ends"
  80.    
  81.     Color 0,0,0
  82.     Locate 0,0
  83.     Print "Starting at ("+x+"/"+a+") And showing ("+y+") lines - Text was readed in ("+newtime+") miliseconds"
  84.    
  85.     Color 255,255,255
  86. End Function
  87.  
  88. Function ShowLines(Start,Length)
  89.     Cls
  90.     Border
  91.        
  92.     For ThisLine.Line = Each Line
  93.    
  94.         ; Checks if start line number + Length number is in the thisline
  95. umber, if yes displays it :
  96.        
  97.         If (thisline
  98. umber>=Start And thisline
  99. umber<=(Start+Length)-1 )
  100.          Print thisline
  101. umber+":"+thislineText$
  102.         End If
  103.    
  104.     Next
  105.  
  106.  
  107. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal