Advertisement
LBASIC

ANSIFUNC.BAS

Jun 5th, 2023
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QBasic 2.83 KB | Software | 0 0
  1.  '|======================  begin ANSIFUNC.BAS  =======================|
  2.  '|  This is a QBasic program to convert an ANSI file to a QBasic     |
  3.  '|  FUNCTION that will return the file as a string. In the program   |
  4.  '|  this program produces, the function is called and the resulting  |
  5.  '|  string is output to CONSOLE, which requires ANSI.SYS loaded.     |
  6.  '|          Released to the Public Domain by Kurt Kuzba              |
  7.  '|===================================================================|
  8.  ' set error trap, set colors, clear screen, q$ = quote mark ==========
  9. ON ERROR GOTO Done: COLOR 2, 0: CLS : q$ = CHR$(34)
  10.  ' create a string for the input boxes  ===============================
  11. i$ = STRING$(16, " ") + STRING$(15, CHR$(29))
  12.  ' print message and get filename from user, open file for input ======
  13. LOCATE 5, 10: PRINT "We will turn an ANSI file into a QBasic function"
  14. LOCATE 6, 10: PRINT "which returns the entire ANSI file as a string."
  15. LOCATE 8, 10: PRINT "Enter ANSI name [ EX. MYPIC.ANS ] ";
  16. COLOR 1, 7: PRINT i$; : INPUT "", ans$: COLOR 2, 0
  17. IF ans$ <> "" THEN OPEN ans$ FOR INPUT AS #1:  ELSE GOTO Done
  18.  ' get name of function to create from user ===========================
  19. LOCATE 10, 10: PRINT "Enter Function name [ EX. Pic1$ ] ";
  20. COLOR 1, 7: PRINT i$; : INPUT "", func$: COLOR 2, 0
  21.  ' make FUNCTION name and open file for input =========================
  22. IF func$ = "" THEN GOTO Done
  23. IF RIGHT$(func$, 1) <> "$" THEN func$ = func$ + "$"
  24. NAME$ = func$ + ".bas": OPEN NAME$ FOR OUTPUT AS #2
  25.  ' write QBasic FUNCTION to file ======================================
  26. PRINT #2, "DECLARE FUNCTION "; func$; "()"
  27. PRINT #2, "open "; q$; "CONS:"; q$; " FOR OUTPUT AS #1"
  28. PRINT #2, "PRINT #1, "; func$
  29. PRINT #2, "FUNCTION "; func$
  30. PRINT #2, "t$ = "; q$; q$
  31.  ' process ANSI to create QBasic routine to construct string ==========
  32. WHILE NOT EOF(1)
  33.    WHILE NOT EOF(1)
  34.       PRINT #2, "t$=t$+"; q$; : C$ = ""
  35.       WHILE C$ <> CHR$(10) AND NOT EOF(1)
  36.          C$ = INPUT$(1, #1)
  37.          IF C$ = CHR$(13) THEN
  38.             C$ = q$ + " + CHR$(13) + CHR$(10)" + CHR$(13) + CHR$(10)
  39.          END IF
  40.          IF C$ <> CHR$(10) THEN PRINT #2, C$;
  41.       WEND
  42.    WEND
  43. WEND
  44.  ' finish writing QBasic FUNCTION to file =============================
  45. PRINT #2, q$
  46. PRINT #2, func$; "=t$"
  47. PRINT #2, "END FUNCTION"
  48.  ' done, tell user new program is ready, wait for key =================
  49. LOCATE 12, 10: COLOR 10
  50. PRINT "Your new program, "; NAME$; ", containing the FUNCTION"
  51. LOCATE 13, 10: PRINT func$; ", to display "; ans$; ", is ready to test."
  52. LOCATE 14, 10: PRINT "ANSI.SYS must be loaded for "; NAME$; " to work."
  53. Done:  CLOSE 1: CLOSE 2: C% = 0: i$ = ""
  54. WHILE i$ = ""
  55.    C% = (C% + 1) AND 15: LOCATE 15, 10: COLOR C%: PRINT "Hit a Key"
  56.    i$ = INKEY$
  57. WEND: COLOR 2
  58.  '|  ===============  end ANSIFUNC.BAS  ==============================|
  59.  
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement