home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Power Pack / Visual_Basic4_Power_Pack.bin / vb4files / ppl4vb20 / vb_io.bas < prev    next >
Encoding:
BASIC Source File  |  1996-11-20  |  5.4 KB  |  243 lines

  1. '
  2. ' -- VB_IO.BAS --
  3. '
  4. ' The display screen is divided up into three parts. The TOP consists
  5. ' of the top 24 rows, numbered 1 to 24. The LEFT consists of the first
  6. ' 35 columns of the last row (row 25). The RIGHT consists of the last
  7. ' 45 columns of the last row.
  8. '
  9. ' All protocol I/O is done to the RIGHT.
  10. '
  11.  
  12. DEFINT A-Z
  13.  
  14. '     vbPutChar : Print a character.
  15. '   vbPutString : Print a string.
  16. '      vbPutEOL : Print a EOL character (clears line).
  17. '   vbPutEOLstr : Print a EOL character then prints string.
  18. '  vbPutInteger : Print integer.
  19. '     vbPutLong : Print long integer.
  20. '  vbPutHexByte : Print byte as hexidecimal number.
  21. '  vbPutHexWord : Print word as hexidecimal number.
  22. '
  23. '    vbKeyPress : Returns TRUE if key has been pressed
  24. '      vbGetKey : Get next keyboard character (wait, no echo)
  25. '   vbGetString : Get a string, echoing.
  26. '
  27. '       vbDebug : Echo to the main display (rows 1 - 24)
  28. '
  29.  
  30. '$INCLUDE: 'CONFIG.BI'
  31. '$INCLUDE: 'MINMAX.BI'
  32. '$INCLUDE: 'VB_IO.BI'
  33.  
  34. CONST False = 0
  35. CONST True = NOT False
  36.  
  37. CONST WHITE = 7
  38. CONST BLACK = 0
  39.  
  40. CONST RightHalf = 36
  41.  
  42. DIM SHARED DebugFlag AS INTEGER
  43.  
  44. DIM SHARED vbCol     AS INTEGER    'current column on right half of row 25
  45. DIM SHARED MainRow   AS INTEGER    'current row on main screen
  46. DIM SHARED MainCol   AS INTEGER    'current column on main screen
  47. DIM SHARED Temp      AS STRING     'temporary string
  48. DIM SHARED LastChar  AS STRING     'last keyboard character
  49.  
  50. SUB vbDebug(BYVAL Flag AS INTEGER)
  51. DebugFlag = Flag
  52. END SUB
  53.  
  54. ' print character
  55.  
  56. SUB vbPutChar(BYVAL Chr AS INTEGER)
  57. IF DebugFlag THEN
  58.   PRINT CHR$(Chr);
  59. END IF
  60. MainRow = CSRLIN
  61. MainCol = POS(0)
  62. VIEW PRINT 25 TO 25
  63. COLOR BLACK, WHITE
  64. LOCATE 25, RightHalf+vbCol, 1
  65. IF vbCol < RightHalf-1 THEN
  66.   PRINT CHR$(Chr);
  67.   vbCol = POS(0) - RightHalf
  68. END IF
  69. VIEW PRINT 1 TO 24
  70. COLOR WHITE, BLACK
  71. LOCATE MainRow, MainCol, 1
  72. END SUB
  73.  
  74. 'print string
  75.  
  76. SUB vbPutString(TheString AS STRING)
  77. DIM L AS INTEGER
  78. IF DebugFlag THEN
  79.   PRINT TheString;
  80. END IF
  81. MainRow = CSRLIN
  82. MainCol = POS(0)
  83. VIEW PRINT 25 TO 25
  84. COLOR BLACK, WHITE
  85. LOCATE 25, RightHalf+vbCol, 1
  86. L = LEN(TheString)
  87. L = MAX(0,MIN(L,40-vbCol))
  88. IF L > 0 THEN
  89.   TheString = LEFT$(TheString,L)
  90.   PRINT TheString;
  91.   vbCol = POS(0) - RightHalf
  92. END IF
  93. VIEW PRINT 1 TO 24
  94. COLOR WHITE, BLACK
  95. LOCATE MainRow, MainCol, 1
  96. END SUB
  97.  
  98. 'print EOL (clears right half of row 25)
  99.  
  100. SUB vbPutEOL()
  101. IF DebugFlag THEN
  102.   PRINT
  103. END IF
  104. MainRow = CSRLIN
  105. MainCol = POS(0)
  106. VIEW PRINT 25 TO 25
  107. COLOR BLACK, WHITE
  108. LOCATE 25,RightHalf
  109. PRINT STRING$(79-RightHalf," ");
  110. vbCol = 0
  111. VIEW PRINT 1 TO 24
  112. COLOR WHITE, BLACK
  113. LOCATE MainRow, MainCol, 1
  114. END SUB
  115.  
  116. 'print EOL then print string
  117.  
  118. SUB vbPutEOLstr(TheString AS STRING)
  119. CALL vbPutEOL
  120. CALL vbPutString(TheString)
  121. END SUB
  122.  
  123. 'print integer
  124.  
  125. SUB vbPutInteger(BYVAL IntValue AS INTEGER)
  126. Temp = STR$(IntValue)
  127. vbPutString(Temp)
  128. END SUB
  129.  
  130. 'print long
  131.  
  132. SUB vbPutLong(BYVAL LongValue AS LONG)
  133. Temp = STR$(LongValue)
  134. vbPutString(Temp)
  135. END SUB
  136.  
  137. 'print hexidecimal byte
  138.  
  139. SUB vbPutHexByte(BYVAL ByteValue AS INTEGER)
  140. Temp = HEX$(&H00FF AND ByteValue)
  141. vbPutString(Temp)
  142. END SUB
  143.  
  144. ' print hexidecimal word
  145.  
  146. SUB vbPutHexWord(BYVAL WordValue AS INTEGER)
  147. Temp = HEX$(ByteValue)
  148. vbPutString(Temp)
  149. END SUB
  150.  
  151. ' test for keypress
  152.  
  153. FUNCTION vbKeyPress() AS INTEGER
  154. IF LastChar <> "" THEN
  155.    vbKeyPress = True
  156.    EXIT FUNCTION
  157. END IF
  158. LastChar = INKEY$
  159. IF LastChar <> "" THEN
  160.    vbKeyPress = True
  161. ELSE
  162.    vbKeyPress = False
  163. END IF
  164. END FUNCTION
  165.  
  166. ' read character from keyboard (no echo)
  167.  
  168. FUNCTION vbGetKey() AS INTEGER
  169. DIM KeyChar AS STRING
  170. DIM Code    AS INTEGER
  171. DIM I       AS INTEGER
  172. ' check character returned by vbKeyPress
  173. IF LastChar = "" THEN
  174.    KeyChar = INPUT$(1)
  175. ELSE
  176.    KeyChar = LastChar
  177.    LastChar = ""
  178. END IF
  179. ' return key value
  180. vbGetKey = ASC(KeyChar)
  181. END FUNCTION
  182.  
  183. ' read message
  184.  
  185. SUB vbGetString(TheString AS STRING)
  186. DIM I AS INTEGER
  187. DIM KeyChar AS INTEGER
  188. I = 0
  189. MainRow = CSRLIN
  190. MainCol = POS(0)
  191. VIEW PRINT 25 TO 25
  192. COLOR BLACK, WHITE
  193. TheString = ""
  194. 'input text from user
  195. LOCATE 25, RightHalf+vbCol, 1
  196.   DO
  197.     IF vbKeyPress THEN
  198.       KeyChar = vbGetKey
  199.       SELECT CASE LEFT$(CHR$(KeyChar), 1)
  200.         CASE CHR$(13)  'CR
  201.           vbCol = POS(0) - RightHalf
  202.           COLOR WHITE, BLACK
  203.           VIEW PRINT 1 TO 24
  204.           LOCATE MainRow, MainCol, 1
  205.           EXIT SUB
  206.         CASE CHR$(27)  'ESC to escape
  207.           'return empty string
  208.           TheString = ""
  209.           COLOR WHITE, BLACK
  210.           VIEW PRINT 1 TO 24
  211.           LOCATE MainRow, MainCol, 1
  212.           EXIT SUB
  213.         CASE CHR$(8) 'backspace
  214.           'back up if can
  215.           IF I > 0 THEN
  216.             'adjust buffer
  217.             I = I - 1
  218.             TheString = LEFT$(TheString, LEN(TheString) - 1)
  219.             'write blank at cursor
  220.             LOCATE 25, RightHalf + vbCol + I, 1
  221.             PRINT " ";
  222.             LOCATE 25, RightHalf + vbCol + I, 1
  223.           END IF
  224.         CASE ELSE 'not one of above special chars
  225.           'display on bottom line
  226.           LOCATE 25, RightHalf + vbCol + I, 1
  227.           PRINT CHR$(KeyChar);
  228.           'save character
  229.           I = I + 1
  230.           TheString = TheString + CHR$(KeyChar)
  231.           'done ?
  232.           IF I >= RightHalf-2 THEN
  233.             Col = RightHalf
  234.             VIEW PRINT 1 TO 24
  235.             COLOR WHITE, BLACK
  236.             LOCATE MainRow, MainCol, 1
  237.             EXIT SUB
  238.           END IF
  239.       END SELECT
  240.     END IF
  241.   LOOP
  242. END SUB
  243.