home *** CD-ROM | disk | FTP | other *** search
AMOS Source Code | 1992-02-26 | 3.9 KB | 188 lines |
- '
- ' NEW INPUT ROUTINES for REAL variables and STRINGS
- '
- '
- ' Written in 1994 by Christian Mumenthaler
- '
- ' These routines are public domain. Use them wherever you want to.
- '
- ' Contact: Christian Mumenthaler
- ' Langgruetstr. 178
- ' CH-8047 Zuerich
- ' Switzerland
- '
- ' E-mail: mumi(at)molbio.ethz.ch
- '
- '
- If Screen Colour<4 : Screen Open 0,320,200,4,0 : Palette 0,$A40,$FFF : End If
- Locate 1,2
- Centre "Example of how to use the routines"
- Print
- Cmove ,2
- Print " REAL NUMBER INPUT: ";
- Pen 0
- Proc R_INPUT[10,0]
- Pen 2
- Print
- Print " (Your input:";Param#;")"
- Print
- Print " INTEGER NUMBER INPUT: ";
- Pen 0
- Proc R_INPUT[6,123]
- Pen 2
- Print
- A=Param#
- Print " (Your input:";A;")"
- Print
- Print " STRING INPUT: ";
- Pen 0
- Proc S_INPUT[12,""]
- Pen 2
- Print
- Print " (Your input:";Param$;")"
- Print
- Print " STRING INPUT (with default): ";
- Pen 0
- Proc S_INPUT[6,"Hallo"]
- Pen 2
- Print
- Print " (Your input:";Param$;")"
- End
- '
- '
- '
- Procedure R_INPUT[L,NR#]
- '
- ' INPUT ROUTINE FOR REAL NUMBERS
- '
- ' L : Length of field
- ' NR# : Default number (Ignored if NR#=0)
- '
- '
- ' This routine accepts only the numbers 0 to 9 and the
- ' characters "." and "-". (Plus RETURN to end and BACKSPACE to
- ' delete the last character.)
- ' It is therefore more fool-proof than the normal INPUT command.
- '
- ' You can also easily change it for INTEGER numbers.
- '
- '
- ' Routine written in 1994 by Christian Mumenthaler
- ' This routine is Public Domain. Use it wherever you want to.
- '
- '
- NA$=""
- If NR#<>0
- NA$=Str$(NR#)
- If Left$(NA$,1)=" "
- NA$=Right$(NA$,Len(NA$)-1)
- End If
- End If
- Z=Len(NA$)
- L1=L-Z
- Print NA$+Space$(L1);
- Cmove -L1,0
- Curs On
- A1=Asc("0") : A2=Asc("9")
- Repeat
- A$=Inkey$
- A$=Upper$(A$)
- A=Asc(A$)
- If((A>=A1 and A<=A2) or(A$=".") or(A$="-" and Z=0)) and Z<L
- Print A$;
- NA$=NA$+A$
- Inc Z
- End If
- If A$=Chr$(8) and Z>0
- Z=Z-1
- Cmove -1,0 : Print " "; : Cmove -1,0
- NA$=Left$(NA$,Len(NA$)-1)
- End If
- Until A$=Chr$(13)
- Curs Off
- A#=Val(NA$)
- End Proc[A#]
- Procedure S_INPUT[L,NA$]
- '
- ' INPUT ROUTINE FOR STRINGS
- '
- ' L : Length of field
- ' NA$ : Default string
- '
- '
- ' This routine accepts all characters that could make sense
- ' (ASC code above 31 and not between 128 and 159)
- ' This routine allows some editing as besides BACKSPACE, it
- ' also processes the RIGHT and LEFT cursor keys, the DELETE
- ' key and the ESC key to reset the default string.
- '
- ' Routine written in 1994 by Christian Mumenthaler
- ' This routine is Public Domain. Use it wherever you want to.
- '
- '
- NA2$=NA$
- XC=X Curs
- YC=Y Curs
- Z=Len(NA$)
- P=Z
- L1=L-Z
- Print NA$+Space$(L1);
- Cmove -L1,0
- Curs On
- Repeat
- Multi Wait
- A$=Inkey$
- ACT=Scancode
- A=Asc(A$)
- If(A>=32 and(A<128 or A>=160)) and Z<L
- NA$=Left$(NA$,P)+A$+Right$(NA$,Z-P)
- NA$=Left$(NA$,L)
- Z=Min(Z+1,L)
- Locate XC,YC
- Print NA$
- Inc P
- Locate XC+P,YC
- End If
- If A=28 and P<L and P<Z
- Cmove 1,
- Inc P
- End If
- If A=29 and P>0
- Cmove -1,
- Dec P
- End If
- '
- ' BACKSPACE
- '
- If A$=Chr$(8) and P>0
- NA$=Left$(NA$,P-1)+Right$(NA$,Z-P)
- Dec Z
- Dec P
- Locate XC,YC
- Print NA$+Space$(L-Len(NA$))
- Locate XC+P,YC
- End If
- '
- ' DELETE
- '
- If ACT=70 and Z>0 and P<Z
- NA$=Left$(NA$,P)+Right$(NA$,Z-P-1)
- Dec Z
- Locate XC,YC
- Print NA$+Space$(L-Len(NA$))
- Locate XC+P,YC
- End If
- '
- ' ESCAPE -> reset to default string
- '
- If A=27
- NA$=NA2$
- Z=Len(NA$)
- P=Z
- Locate XC,YC
- Print NA$;Space$(L-Z);
- Locate XC+P,YC
- End If
- Until A$=Chr$(13)
- Curs Off
- End Proc[NA$]