home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / 1989 / 02 / heimwerk / makemenu.bas < prev    next >
Encoding:
BASIC Source File  |  1988-11-11  |  5.7 KB  |  190 lines

  1. REM * ---------------------------------------------------- *
  2. REM *                 MAKEMENU.BAS                         *
  3. REM *      Menuegenerator für Turbo/Quick Basic            *
  4. REM *               (c) 1988  TOOLBOX                      *
  5. REM * ---------------------------------------------------- *
  6.  
  7. DEF FNPrintLine$ (S$, Max%)
  8.   LOCAL j%, Zeile$              ' (Für Quick Basic: STATIC)
  9.  
  10.   Zeile$ = S$
  11.   FOR j% = 1 TO Max% - Len(S$)
  12.     Zeile$ = Zeile$ + " "
  13.   NEXT j%
  14.   FNPrintLine$ = Zeile$
  15.  
  16. END DEF
  17.  
  18.  
  19. CLS
  20. COLOR 15, 1
  21. LOCATE 1,30 : PRINT "Menuegenerator"
  22. LOCATE 4,10 : PRINT "Wieviele Punkte soll das Menue haben ";
  23. CALL Eingabe(2, 50, 4, "w", antwort$)
  24. pkte% = VAL(antwort$)
  25.  
  26. DIM menue$(pkte%)
  27.  
  28. LOCATE 6,10 : PRINT "Bitte geben Sie die Stichworte ein: ";
  29. LOCATE 8,10 : PRINT "Punkt ";
  30. FOR i% = 1 TO pkte%
  31.   LOCATE 8,16: PRINT i%; ": "
  32.   CALL Eingabe(40, 20, 8, "t", antwort$)
  33.   menue$(i%) = antwort$
  34. NEXT i%
  35. CLS
  36. LOCATE 1,30 : PRINT "Menuegenerator"
  37. LOCATE 4,10 : PRINT "Koordinaten der linken oberen Ecke ?";
  38. LOCATE 6,10 : PRINT "x: ";
  39. CALL Eingabe(2, 13, 6, "w", antwort$)
  40. ox% = VAL(antwort$)
  41. LOCATE 7,10 : PRINT "y: ";
  42. CALL Eingabe(2, 13, 7, "w", antwort$)
  43. oy% = VAL(antwort$)
  44. LOCATE 9,10 : PRINT "Wie soll die Datei heißen ? "
  45. CALL Eingabe(11, 38, 9, "t", antwort$)
  46. Dateiname$ = antwort$
  47. LOCATE 10,10 : PRINT "Und das Menue ? "
  48. CALL Eingabe(10, 38, 10, "t", antwort$)
  49. Menuename$ = antwort$ + "$"
  50.  
  51. OPEN Dateiname$ FOR OUTPUT AS #1
  52.   REM PRINT #1, "DECLARE SUB PopUpMenue (x%, y%, Texte$(1)";
  53.   REM PRINT #1, ", Items%, Mono%, Res%, Res$)"
  54.   PRINT #1, "DIM ";Menuename$;" (";pkte%;")"
  55.   FOR i% = 1 TO pkte%
  56.     PRINT #1, Menuename$; "(" ; i%; ") = "; CHR$(34);
  57.     PRINT #1, menue$(i%); CHR$(34)
  58.   NEXT i%
  59.   PRINT #1, CHR$(13)
  60.   PRINT #1, "CALL PopUpMenue(";ox%;",";oy%;",";Menuename$;
  61.   PRINT #1, "(),";pkte%;",0,Res%,Res$)"
  62.   PRINT #1, "REM Das Ergebnis steht jetzt in a% und a$"
  63.   OPEN "POPUP.INC" FOR INPUT AS #2
  64.     WHILE NOT EOF(2)
  65.       LINE INPUT #2, Prozedurzeile$
  66.       PRINT #1, Prozedurzeile$
  67.     WEND
  68.   CLOSE #2
  69. CLOSE #1
  70. LOCATE 12,10: PRINT "Okay, das war's..."
  71. END
  72.  
  73. SUB Eingabe(feldlen%, spos%, zpos%, vartyp$, antwort$)
  74.  
  75.   LOCAL sammel$       'sammelt die geprüften Zeichen
  76.   LOCAL taste$        'für das letzte eingegebene Zeichen
  77.   LOCAL dezimal%      'Schalter für Dezimalpunkt
  78.   LOCAL muell$        'Dummy zum Löschen des Tastaturpuffers
  79.   LOCAL punkte%       'zum Aufbau des Eingabefeldes
  80.   LOCAL punkte$, schleife%
  81.  
  82.   REM In Quick Basic müssen die LOCAL-Deklarationen
  83.   REM wegfallen, weil die Variablen in einer Prozedur
  84.   REM per Default Lokal sind
  85.  
  86.   taste$ = CHR$(1)            'Einstieg in die Hauptschleife
  87.   IF zpos% < 1 OR zpos% > 25 THEN GOSUB Fehler
  88.   IF spos% < 1 OR spos% > 80 THEN GOSUB Fehler
  89.   IF feldlen% < 1 OR feldlen% > (79 - spos%) THEN
  90.     GOSUB Fehler
  91.   END IF
  92.   IF vartyp$ <> "t" AND vartyp$ <> "w" THEN GOSUB Fehler
  93.  
  94.   LOCATE zpos%, spos%
  95.   PRINT CHR$(242);               'Zeichen für den Prompt "≥"
  96.   PRINT STRING$(feldlen%, "_");
  97.  
  98.   WHILE taste$ <> CHR$(13)         'Verlassen mit < RETURN >
  99.     taste$ = ""
  100.     WHILE taste$ = ""
  101.       taste$ = INKEY$         'Warte und hole erstes Zeichen
  102.     WEND
  103.     muell$ = INKEY$
  104.     IF muell$ = "" THEN GOSUB Abfrage  'Tastaturpuffer  leer
  105.     WHILE muell$ <> ""
  106.       muell$ = INKEY$                'Löschen Tastaturpuffer
  107.     WEND
  108.   WEND
  109.   antwort$ = sammel$                 'Ergebnis bereitstellen
  110.   GOTO Feierabend                    'Unterprogramme werden
  111.                                      'übersprungen
  112.  
  113. REM * ---------------------------------------------------- *
  114. Abfrage:
  115.   DO
  116.     IF ASC(taste$)=27 OR ASC(taste$)=13 THEN GOTO ExitLoop
  117.     IF ASC(taste$)<13 AND ASC(taste$)<>8 THEN GOTO ExitLoop
  118.     IF ASC(taste$) = 8 AND sammel$ = "" THEN GOTO ExitLoop
  119.     IF ASC(taste$) = 8 AND RIGHT$(sammel$, 1) = "." THEN
  120.       dezimal% = 0
  121.     END IF
  122.     IF ASC(taste$) = 8 THEN
  123.       GOSUB Backspace
  124.       GOTO Update
  125.     END IF
  126.  
  127.     IF LEN(sammel$) = feldlen% THEN GOTO ExitLoop
  128.  
  129.     schleife% = -1
  130.     WHILE vartyp$ = "w" AND schleife% = -1
  131.  
  132.       IF taste$ = "," THEN taste$ = "."      'Komma -> Punkt
  133.  
  134.       IF dezimal% = 0 AND ASC(taste$) = 46 THEN
  135.         dezimal% = 1               'Dezimalflag setzen
  136.         GOTO EndWhile
  137.       END IF
  138.  
  139.       IF dezimal% = 1 AND ASC(taste$) = 46 THEN
  140.         taste$ = ""
  141.         GOTO EndWhile
  142.       END IF
  143.  
  144.       IF taste$ = "-" AND sammel$ = "" THEN GOTO EndWhile
  145.                                          'erstes zeichen "-"
  146.  
  147.       IF ASC(taste$) > 47 AND ASC(taste$) < 58 THEN
  148.         GOTO EndWhile
  149.       END IF                          'nur Ziffern zulassen
  150.  
  151.       taste$ = ""               'Falsche Eingabe, ignorieren
  152.       EndWhile:
  153.       schleife% = 0
  154.     WEND
  155.  
  156.     sammel$ = sammel$ + taste$
  157.                               'Anfügen des gültigen Zeichens
  158. Update:
  159.     taste$ = ""
  160.     punkte% = feldlen% - LEN(sammel$)  'Update Eingabefeldes
  161.     IF punkte% <= 0 THEN                     '...am Feldende
  162.       punkte$ = ""
  163.     ELSE
  164.       punkte$ = STRING$(punkte% - 1, "_")
  165.     END IF
  166.     LOCATE zpos%, spos%
  167.     PRINT sammel$;                     '...bisherige Eingabe
  168.     PRINT CHR$(242);                   '...Prompt "≥"
  169.     PRINT punkte$; " ";                '...Unterstriche
  170.   LOOP UNTIL 1 = 1             'Bedingung für Endlosschleife
  171.   ExitLoop:
  172. RETURN
  173.  
  174. REM * ---------------------------------------------------- *
  175. Backspace:
  176.   sammel$ = LEFT$(sammel$, LEN(sammel$) - 1)
  177. RETURN
  178.  
  179. Fehler:
  180.   LOCATE 25, 2
  181.   BEEP: BEEP: BEEP
  182.   PRINT "Fehlerhafte Parameterübergabe, Programmabbruch"
  183.   END
  184. RETURN
  185.  
  186. Feierabend:
  187.   END SUB
  188.  
  189. REM * ---------------------------------------------------- *
  190.