home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Basic / MAXONB32.DMS / in.adf / Beispiele_1.3 / Examples / GetString.bas < prev    next >
Encoding:
BASIC Source File  |  1994-04-14  |  4.0 KB  |  122 lines

  1.  
  2. '
  3. ' Get.String
  4. '
  5. ' written by   scott dhomas trenn
  6. '              797 Mitchell Street, Fredericton, NB, E3B 3S8, CANADA
  7. '              INTERNET: wilkie@jupiter.sun.csd.unb.ca
  8. '
  9. ' "Roll your own" String Requesters.
  10. '
  11. ' Parameters:
  12. '  SX = Window X position to begin text input
  13. '  SY = Window Y position to begin text input
  14. '  CharWidth = Font Width
  15. '  InputString$ = Initial string contents
  16. '  Length = Maximum length of input string
  17. '  Capitalize = YES (-1) : Converts input to all capitals
  18. '               NO  (0)  : Input stays as entered
  19. '  Color1 = Cursor color
  20. '  Color2 = Foreground color to display when inputting
  21. '  Color3 = Background color to display when inputting
  22. '
  23. '
  24. ' Full edit capability... CRSR LEFT/RIGHT, DEL, BACKSPACE, etc.
  25. ' Adds ability to use CRSR UP/DOWN for multiple strings (LINE 94)
  26. '
  27.  
  28. DEFINT A-Z
  29. CONST NO = 0
  30.  
  31. ' Example 1 - Single gadget
  32.  
  33. iString$ = ""
  34. LINE (5,1)-(180,14),1,b
  35. Get.String 10,10,8,iString$,20,NO,1,2,0
  36.  
  37. CLS
  38.  
  39.  
  40. ' Example 2 - Multiple gadgets with CRSR UP-DOWN
  41.  
  42. Artist$ = "Artist" : Title$ = "Title" : Type$ = ""
  43. LINE (5,1)-(180,14),1,b : PRINT PTAB(10,10);Artist$;
  44. LINE (5,16)-(180,29),1,b : PRINT PTAB(10,25);Title$;
  45. LINE (5,31)-(180,44),1,b : PRINT PTAB(10,40);Type$;
  46.  
  47. Get.1:
  48.         Get.String 10,10,8,Artist$,20,NO,1,2,0
  49.         IF iKey = 28 THEN Get.3 ' CRSR DOWN
  50.         IF iKey = 29 THEN Get.2 ' CRSR UP
  51.         IF iKey = 27 THEN Show.Results ' ESCAPE
  52. Get.2:
  53.         Get.String 10,25,8,Title$,20,NO,1,2,0
  54.         IF iKey = 28 THEN Get.1
  55.         IF iKey = 29 THEN Get.3
  56.         IF iKey = 27 THEN Show.Results
  57. Get.3:
  58.         Get.String 10,40,8,Type$,20,NO,1,2,0
  59.         IF iKey = 28 THEN Get.2
  60.         IF iKey = 29 THEN Get.1
  61.  
  62.  
  63. ' Show all the result strings
  64. Show.Results:
  65.         CLS : COLOR 1,0
  66.         PRINT "iString$ = ";iString$
  67.         PRINT
  68.         PRINT "Artist$  = ";Artist$
  69.         PRINT "Title$   = ";Title$
  70.         PRINT "Type$    = ";Type$
  71. END
  72.  
  73.  
  74. SUB Get.String (VAL SX,VAL SY,VAL CharWidth,InputString$,VAL Length,VAL Capitalize,VAL Color1,VAL Color2,VAL Color3) STATIC
  75.  
  76.         SHARED iKey
  77.         Position = LEN(InputString$)
  78.                 COLOR Color2,Color3 : PRINT PTAB(SX,SY);LEFT$(InputString$+SPACE$(Length), Length);
  79. Position.Cursor:
  80.         IF Position + 1 > LEN(InputString$) THEN
  81.                 Character$ = " "
  82.         ELSE
  83.                 Character$ = MID$(InputString$,Position + 1,1)
  84.         END IF
  85.         PRINT PTAB(SX+Position*CharWidth,SY);
  86.         COLOR Color2,Color1: PRINT Character$;
  87.         PRINT PTAB(SX+Position*CharWidth,SY);
  88.         COLOR Color2,Color3
  89. Get.Key:
  90.         iKey$ = INKEY$: IF iKey$ = "" THEN Get.Key
  91.         iKey = ASC(iKey$)
  92.         IF iKey > 31 AND iKey < 127 AND iKey <> 34 AND LEN(InputString$) < Length THEN
  93.                 IF Capitalize THEN iKey$ = UCASE$(iKey$)
  94.                 InputString$ = LEFT$(InputString$,Position) + iKey$ + RIGHT$(InputString$,LEN(InputString$)-Position)
  95.                 PRINT RIGHT$(InputString$,LEN(InputString$)-Position);
  96.                 INCR Position
  97.         ELSEIF iKey = 13 OR iKey = 27 OR iKey = 28 OR iKey = 29 THEN
  98.                 PRINT Character$;
  99.                 EXIT SUB
  100.         ELSEIF iKey = 8 AND LEN(InputString$) <> 0 AND Position <> 0 THEN
  101.                 PRINT Character$;
  102.                 PRINT PTAB(SX+(Position-1)*CharWidth,SY);
  103.                 PRINT RIGHT$(InputString$,LEN(InputString$)-Position);" ";
  104.                 InputString$ = LEFT$(InputString$,Position-1) + RIGHT$(InputString$,LEN(InputString$)-Position)
  105.                 DECR Position
  106.         ELSEIF iKey = 127 AND LEN(InputString$) <> 0 AND Position < LEN(InputString$) THEN
  107.                 InputString$ = LEFT$(InputString$,Position) + RIGHT$(InputString$,LEN(InputString$)-Position-1)
  108.                 PRINT RIGHT$(InputString$,LEN(InputString$)-Position);" ";
  109.         ELSEIF iKey = 31 AND Position <> 0 THEN
  110.                 PRINT Character$;
  111.                 DECR Position
  112.         ELSEIF iKey = 30 AND Position <> LEN(InputString$) THEN
  113.                 PRINT Character$;
  114.                 INCR Position
  115.         ELSE
  116.                 GOTO Get.Key
  117.         END IF
  118.         GOTO Position.Cursor
  119.  
  120. END SUB
  121.  
  122.