home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / basic / tsrbas20.zip / NOTEPAD.BAS < prev    next >
BASIC Source File  |  1991-04-03  |  6KB  |  275 lines

  1. 1000 ' NotePad, Version 2.0
  2. 1010 '
  3. 1020 ' Press esc to terminate and stay resident
  4. 1030 ' Press control-shift-b from dos to resume notepad
  5. 1040 ' Press end to terminate notepad
  6. 1050 '
  7. 1060 on error goto 3670
  8. 1070 gosub 1150 ' initialize
  9. 1080 gosub 1570 ' display banner
  10. 1090 gosub 1800    ' read file
  11. 1100 gosub 2200    ' display command window
  12. 1110 gosub 2350    ' display note window
  13. 1120 gosub 2450 ' display note
  14. 1130 gosub 2510 ' process command
  15. 1140 goto 1130
  16. 1150 '
  17. 1160 ' subroutine to initialize everything
  18. 1170 '
  19. 1180 dim notes (100)
  20. 1190 pathname = "notepad.dat"
  21. 1200 init
  22. 1210 cls
  23. 1220 csroff
  24. 1230 foreground lookup ("white")
  25. 1240 background lookup ("blue")
  26. 1250 intensity lookup ("high")
  27. 1260 '
  28. 1270 ' banner window
  29. 1280 '
  30. 1290 ban_top = 1
  31. 1300 ban_left = 1
  32. 1310 ban_bottom = 1
  33. 1320 ban_right = 40
  34. 1330 cnt_col = 23
  35. 1340 cnt_len = ban_right - cnt_col 
  36. 1350 '
  37. 1360 ' command window
  38. 1370 '
  39. 1380 cmd_top = 5
  40. 1390 cmd_left = 1
  41. 1400 cmd_bottom = 10
  42. 1410 cmd_right = 17
  43. 1420 '
  44. 1430 ' notepad text window
  45. 1440 '
  46. 1450 txt_top = 13
  47. 1460 txt_left = 0
  48. 1470 txt_bottom = 22
  49. 1480 txt_right = 78
  50. 1490 '
  51. 1500 ' message window
  52. 1510 '
  53. 1520 msg_top = 6
  54. 1530 msg_left = 30
  55. 1540 msg_bottom = 10
  56. 1550 msg_right = 70
  57. 1560 return
  58. 1570 '
  59. 1580 ' subroutine to display banner
  60. 1590 '
  61. 1600 wintop ban_top-1
  62. 1610 winleft ban_left-1
  63. 1620 winright ban_right+1
  64. 1630 winbottom ban_bottom+1
  65. 1640 border
  66. 1650 cls
  67. 1660 display ban_top, ban_left, "NotePad, Version 1.0, "
  68. 1670 return
  69. 1680 '
  70. 1690 ' subroutine to update record count
  71. 1700 '
  72. 1710 display ban_top, cnt_col, space (cnt_len)
  73. 1720 if rec = 0
  74. 1730    then
  75. 1740       msg = "Top of NotePad"
  76. 1750    else
  77. 1760       msg = "Note " + rec + " of " + tot
  78. 1770 end if
  79. 1780 display ban_top, cnt_col, msg
  80. 1790 return
  81. 1800 '
  82. 1810 ' subroutine to read file
  83. 1820 '
  84. 1830 rec = 0
  85. 1840 tot = 0
  86. 1850 temp = ""
  87. 1860 notes (0) = ""
  88. 1870 if not access (pathname) then return
  89. 1880 open #1, "r", pathname
  90. 1890 if not eof (1)
  91. 1900    then 
  92. 1910       line input #1, buf
  93. 1920       if buf = ".endnote"
  94. 1930          then
  95. 1940             tot = tot + 1
  96. 1950             notes(tot) = temp
  97. 1960             temp = ""
  98. 1970          else
  99. 1980             if temp = ""
  100. 1990                then
  101. 2000                   temp = buf
  102. 2010                else
  103. 2020                   temp = temp + chr(10) + buf
  104. 2030             end if
  105. 2040       end if   
  106. 2050       goto 1890
  107. 2060 end if
  108. 2070 close #1
  109. 2080 rec = tot
  110. 2090 return
  111. 2100 ' 
  112. 2110 ' subroutine to write file
  113. 2120 '
  114. 2130 open #1, "w", pathname
  115. 2140 for i = 1 to tot
  116. 2150    print #1, notes(i)
  117. 2160    print #1, ".endnote"
  118. 2170 next i
  119. 2180 close #1
  120. 2190 '
  121. 2200 ' subroutine to open command window
  122. 2210 '
  123. 2220 wintop cmd_top-1
  124. 2230 winleft cmd_left-1
  125. 2240 winbottom cmd_bottom+1
  126. 2250 winright cmd_right+1
  127. 2260 border
  128. 2270 cls
  129. 2280 display cmd_top,   cmd_left, "Ins - Insert Note"
  130. 2290 display cmd_top+1, cmd_left, "Del - Delete Note"
  131. 2300 display cmd_top+2, cmd_left, "End - Exit"
  132. 2310 display cmd_top+3, cmd_left, "Esc - Suspend"
  133. 2320 display cmd_top+4, cmd_left, chr(0x18) + "   - Move Up"
  134. 2330 display cmd_top+5, cmd_left, chr(0x19) + "   - Move Down"
  135. 2340 return
  136. 2350 '
  137. 2360 ' subroutine to open note window
  138. 2370 '
  139. 2380 wintop txt_top
  140. 2390 winleft txt_left
  141. 2400 winbottom txt_bottom
  142. 2410 winright txt_right
  143. 2420 border
  144. 2430 cls
  145. 2440 return
  146. 2450 '
  147. 2460 ' subroutine to display note
  148. 2470 '
  149. 2480 locate 0,0
  150. 2490 print notes(rec)
  151. 2500 return
  152. 2510 ' 
  153. 2520 ' subroutine to get and process command keys
  154. 2530 '
  155. 2540 gosub 1680 ' update record count
  156. 2550 row cmd_top
  157. 2560 column cmd_left
  158. 2570 key = getkey ()
  159. 2580 if key = 0x011b then gosub 2660 : return   ' escape
  160. 2590 if key = 0x4f00 then gosub 2780 : return   ' end
  161. 2600 if key = 0x4800 then gosub 2860 : return    ' up
  162. 2610 if key = 0x5000 then gosub 2940 : return    ' down
  163. 2620 if key = 0x5200 then gosub 3200 : return    ' insert
  164. 2630 if key = 0x5300 then gosub 3550 : return    ' delete
  165. 2640 beep
  166. 2650 return
  167. 2660 '
  168. 2670 ' subroutine to suspend
  169. 2680 '
  170. 2690 gosub 2100 ' write file
  171. 2700 csron
  172. 2710 init
  173. 2720 savescreen old_screen
  174. 2730 cls
  175. 2740 suspend
  176. 2750 restorescreen old_screen
  177. 2760 csroff
  178. 2770 return
  179. 2780 '
  180. 2790 ' subroutine to terminate
  181. 2800 '
  182. 2810 gosub 2100 ' write file
  183. 2820 csron
  184. 2830 init 
  185. 2840 cls 
  186. 2850 end
  187. 2860 '
  188. 2870 ' subroutine to move up
  189. 2880 '
  190. 2890 if rec = 0 then : beep : return
  191. 2900 rec = rec - 1
  192. 2910 gosub 2350 ' open note window
  193. 2920 gosub 2450 ' display note
  194. 2930 return
  195. 2940 '
  196. 2950 ' subroutine to move down
  197. 2960 '
  198. 2970 if rec >= tot then beep : return
  199. 2980 rec = rec + 1
  200. 2990 gosub 2350 ' open note window
  201. 3000 gosub 2450 ' display note
  202. 3010 return
  203. 3020 '
  204. 3030 ' subroutine to display a message
  205. 3040 '
  206. 3050 wintop msg_top
  207. 3060 winleft msg_left
  208. 3070 winbottom msg_bottom
  209. 3080 winright msg_right
  210. 3090 fore = foreground (lookup ("white"))
  211. 3100 back = background (lookup ("red"))
  212. 3110 brightness = intensity (lookup ("high"))
  213. 3120 border
  214. 3130 cls
  215. 3140 locate 0, 0
  216. 3150 print msg
  217. 3160 foreground fore
  218. 3170 background back
  219. 3180 intensity brightness
  220. 3190 return
  221. 3200 ' 
  222. 3210 ' subroutine to insert a note
  223. 3220 '
  224. 3230 msg = "Enter note, followed by extra return"
  225. 3240 gosub 3020 ' display message
  226. 3250 gosub 2350 ' open note window
  227. 3260 csron
  228. 3270 new_note = ""
  229. 3280 line input buf
  230. 3290 if buf <> ""
  231. 3300    then
  232. 3310       if new_note = ""
  233. 3320          then
  234. 3330             new_note = buf
  235. 3340          else
  236. 3350             new_note = new_note + chr (10) + buf
  237. 3360       end if
  238. 3370       goto 3280
  239. 3380 end if
  240. 3390 if new_note <> ""
  241. 3400    then
  242. 3410       rec = rec + 1
  243. 3420       tot = tot + 1
  244. 3430       for i = tot to rec+1 step -1
  245. 3440          notes (i) = notes (i-1)
  246. 3450       next i
  247. 3460       notes (rec) = new_note
  248. 3470       msg = "Note added"
  249. 3480    else
  250. 3490       gosub 2450 ' display note
  251. 3500       msg = "Note cancelled" 
  252. 3510 end if
  253. 3520 gosub 3020 ' display message
  254. 3530 csroff
  255. 3540 return
  256. 3550 '
  257. 3560 ' subroutine to delete a note
  258. 3570 '
  259. 3580 if rec = 0 or tot = 0 then beep : return
  260. 3590 tot = tot - 1
  261. 3600 for i = rec to tot
  262. 3610    notes (i) = notes (i+1)
  263. 3620 next i
  264. 3630 rec = rec - 1
  265. 3640 gosub 2350 ' open note window
  266. 3650 gosub 2450 ' display note
  267. 3660 return
  268. 3670 '
  269. 3680 ' error handler
  270. 3690 ' 
  271. 3700 init
  272. 3710 cls
  273. 3720 print "ERROR: "; erm(); " at "; erl()
  274. 3730 end
  275.