home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / QBAS / VBUTIL.ZIP / PSCRNLIB.BAS < prev    next >
BASIC Source File  |  1992-10-06  |  5KB  |  182 lines

  1. Sub InitScreen (MaxRow%, MaxCol%, SD As ScreenType)
  2.   ' initialize screen parameters
  3.   SD.MaxCols = MaxCol%
  4.   SD.MaxRows = MaxRow%
  5.   SD.CursX = 1
  6.   SD.CursY = 1
  7. End Sub
  8.  
  9. Sub ClearScreen (TBox As Control, SL$(), SD As ScreenType)
  10.   ' clear the screen by assigning empty strings to the
  11.   ' TBox and SL$ array and setting the cursor variables to 1.
  12.   Dim I As Integer
  13.   If TypeOf TBox Is TextBox Then
  14.     TBox.Text = ""
  15.     For I = 1 To SD.MaxRows
  16.       SL$(I) = ""
  17.     Next I
  18.     SD.CursX = 1
  19.     SD.CursY = 1
  20.   End If
  21. End Sub
  22.  
  23. Sub GotoXY (X%, Y%, SL$(), SD As ScreenType)
  24.   ' move the hidden cursor to (X%, Y%)
  25.   Dim L As Integer
  26.   If (X% < 1) Or (Y% < 1) Then Exit Sub
  27.   If (Y% > SD.MaxRows) Or (X% > SD.MaxCols) Then Exit Sub
  28.   L = Len(SL$(Y%))
  29.   If X% > L Then
  30.     SL$(Y%) = SL$(Y%) + Space$(X% - L)
  31.   End If
  32.   SD.CursX = X%
  33.   SD.CursY = Y%
  34. End Sub
  35.  
  36. Function WhereX (SD As ScreenType) As Integer
  37.   ' return the value of SD.CursX
  38.   WhereX = SD.CursX
  39. End Function
  40.  
  41. Function WhereY (SD As ScreenType) As Integer
  42.   ' return the value of the SD.CursY
  43.   WhereY = SD.CursY
  44. End Function
  45.  
  46. Sub ScrollUp (NumLines%, TBox As Control, SL$(), SD As ScreenType)
  47.   ' scroll up a specified number of lines
  48.   Dim I As Integer
  49.   If TypeOf TBox Is TextBox Then
  50.   Else
  51.     Exit Sub
  52.   End If
  53.   If NumLines < 1 Then Exit Sub
  54.   ' scroll at most SD.MaxRows
  55.   If NumLines > SD.MaxRows Then
  56.     NumLines = SD.MaxRows
  57.   End If
  58.   ' copy leading string to emulate scroll
  59.   For I = 1 To SD.MaxRows - NumLines
  60.     SL$(I) = SL$(I + NumLines)
  61.   Next I
  62.   ' assign empty string to trailing strings
  63.   For I = SD.MaxRows - NumLines + 1 To SD.MaxRows
  64.     SL$(I) = ""
  65.   Next I
  66.   UpdateScreenText TBox, SL$(), SD
  67. End Sub
  68.  
  69. Sub NewLine (TBox As Control, SL$(), SD As ScreenType)
  70.   ' move the hidden cursor to the first column of
  71.   ' the next line.  Scroll screen up if the cursor
  72.   ' is already at the last allowed screen row
  73.   If TypeOf TBox Is TextBox Then
  74.     If SD.CursY < SD.MaxRows Then
  75.       SD.CursY = SD.CursY + 1
  76.       SD.CursX = 1
  77.     Else
  78.       ScrollUp 1, TBox, SL$(), SD
  79.       SD.CursX = 1
  80.     End If
  81.   End If
  82. End Sub
  83.  
  84. Sub PPrint (S$, UpdateScreenNow%, TBox As Control, SL$(), SD As ScreenType)
  85.   ' Emulate a simple form of the QuickBasic print:
  86.   '
  87.   '            PRINT Astring$;
  88.   '
  89.   ' The second parameter enable you to update the text
  90.   ' on the screen, or keep the changes hidden (for now).
  91.   Dim LenStr As Integer
  92.   Dim LenLine As Integer
  93.   Dim LenDiff As Integer
  94.   Dim S2 As String
  95.   If TypeOf TBox Is TextBox Then
  96.   Else
  97.     Exit Sub
  98.   End If
  99.   If S$ = "" Then Exit Sub
  100.   LenStr = Len(S$)
  101.   If SD.CursY = SD.MaxRows Then ScrollUp 1
  102.   LenLine = Len(SL$(SD.CursY))
  103.   S2 = ""
  104.   ' string cannot fit on the current line?
  105.   If (SD.CursX + LenStr) > SD.MaxCols Then
  106.     LenDiff = SD.CursX + LenStr - SD.MaxCols - 1
  107.     ' split original string into two strings
  108.     S2 = Right$(S$, LenDiff) ' next-line text
  109.     S$ = Left$(S$, LenStr - LenDiff)
  110.   End If
  111.   ' Pad current line
  112.   If (SD.CursX + LenStr) > LenLine Then
  113.     LenDiff = SD.CursX + LenStr - LenLine
  114.     SL$(SD.CursY) = SL$(SD.CursY) + Space$(LenDiff)
  115.   End If
  116.   ' write S to current line
  117.   Mid$(SL$(SD.CursY), SD.CursX, LenStr) = S$
  118.   SD.CursX = SD.CursX + LenStr
  119.   ' the next-line string is not empty?
  120.   If SD.CursX > SD.MaxCols Then NewLine TBox, SL$(), SD
  121.   If S2 <> "" Then ' print to the next line
  122.     If SD.CursY < SD.MaxCols Then NewLine TBox, SL$(), SD
  123.     LenDiff = Len(S2) - Len(SL$(SD.CursY))
  124.     If LenDiff > 0 Then ' pad the string for the next line
  125.       SL$(SD.CursY) = SL$(SD.CursY) + Space$(LenDiff)
  126.     End If
  127.     ' write the next-line string
  128.     Mid$(SL$(SD.CursY), 1, Len(S2)) = S2
  129.     SD.CursX = Len(S2) + 1
  130.     If SD.CursX > SD.MaxCols Then NewLine TBox, SL$(), SD
  131.   End If
  132.   ' update the screen now?
  133.   If UpdateScreenNow% Then UpdateScreenText TBox, SL$(), SD
  134. End Sub
  135.  
  136. Sub SaveScreen (Buff$(), BufData As ScreenType, SL$(), SD As ScreenType)
  137.   ' save screen to Buff$() array.
  138.   ' the current position of the hidden cursor is
  139.   ' stored in the fields of the SD parameter
  140.   Dim I As Integer
  141.   For I = 1 To SD.MaxRows
  142.     Buff$(I) = SL$(I)
  143.   Next I
  144.   BufData.MaxRows = SD.MaxRows
  145.   BufData.MaxCols = SD.MaxCols
  146.   BufData.CursX = SD.CursX
  147.   BufData.CursY = SD.CursY
  148. End Sub
  149.  
  150. Sub LoadScreen (TBox As Control, Buff$(), BufData As ScreenType, SL$(), SD As
  151. ScreenType)
  152.   ' load screen from the Buff$() array
  153.   ' the fields of the SD parameters specify new cursor location
  154.   Dim I As Integer
  155.   If TypeOf TBox Is TextBox Then
  156.     For I = 1 To SD.MaxRows
  157.       SL$(I) = Buff$(I)
  158.     Next I
  159.     SD.MaxRows = BufData.MaxRows
  160.     SD.MaxCols = BufData.MaxCols
  161.     SD.CursX = BufData.CursX
  162.     SD.CursY = BufData.CursY
  163.     UpdateScreenText TBox, SL$(), SD
  164.   End If
  165. End Sub
  166.  
  167. Sub UpdateScreenText (TBox As Control, SL$(), SD As ScreenType)
  168.   ' update the text in the TBox
  169.   Dim I As Integer
  170.   Dim S As String
  171.   Dim NL As String * 2
  172.   If TypeOf TBox Is TextBox Then
  173.     NL = Chr$(13) + Chr$(10)
  174.     S = ""
  175.     For I = 1 To SD.MaxRows - 1
  176.       S = S + SL$(I) + NL
  177.     Next I
  178.     S = S + SL$(SD.MaxRows)
  179.     TBox.Text = S
  180.   End If
  181. End Sub
  182.