Re: DAU-Fragen
Verfasst: 22.10.2004 08:18
Wenn Du möchtest kannst Du mein WaitKey dafür nehmen.pbdau hat geschrieben:Ich habe an einem Beispiel gesehen, dass man über die
Konsole per input() Strings Zeichen eingeben kann.
Wie kann ich nur Zahlen eingeben (Variablen?) und z.B.
prüfen, ob die Zahl maximal zweistellig ist?
Das Original:
Code: Alles auswählen
; "Console WaitKey.pb"
;
; by Danilo, 03.12.2003
;
Procedure.l WaitKey()
; waits until the user presses a key
Repeat
asc = Asc(Inkey())
If asc > 0 And asc < 127
key = asc
EndIf
Delay(10)
Until key
ProcedureReturn key
EndProcedure
Procedure.l WaitKey2(string$)
; waits until the users presses a key
; specified in string$
Repeat
asc = Asc(Inkey())
If asc > 0 And asc < 127
If FindString(string$,Chr(asc),1)
key = asc
EndIf
EndIf
Delay(10)
Until key
ProcedureReturn key
EndProcedure
OpenConsole()
PrintN(""):Print("Input? ")
For a = 1 To 10 ; get 10 chars with WaitChar
key = WaitKey()
If key=13
Break
ElseIf key > 31
Print(Chr(key))
EndIf
Next a
PrintN(""):Print("Number? ")
For a = 1 To 10
key = WaitKey2("0123456789."+Chr(13))
If key=13 ; return
Break
EndIf
Print(Chr(key))
Next a
3-stellige Zahl:
Code: Alles auswählen
Procedure.l WaitKey2(string$)
; waits until the users presses a key
; specified in string$
Repeat
asc = Asc(Inkey())
If asc > 0 And asc < 127
If FindString(string$,Chr(asc),1)
key = asc
EndIf
EndIf
Delay(10)
Until key
ProcedureReturn key
EndProcedure
OpenConsole()
PrintN(""):Print("Bitte geben sie eine 3-stellige Nummer ein: ")
For a = 1 To 3
key = WaitKey2("0123456789"+Chr(13))
If key=13 ; return
Break
EndIf
Print(Chr(key))
num$+Chr(key)
Next a
PrintN(""):PrintN(""):PrintN("Ihre Nummer: "+num$)
PrintN("<return>")
WaitKey2(Chr(13))
Debug Val(num$)
Code: Alles auswählen
Procedure.l WaitKey2(string$)
; waits until the users presses a key
; specified in string$
Repeat
asc = Asc(Inkey())
If asc > 0 And asc < 127
If FindString(string$,Chr(asc),1)
key = asc
EndIf
EndIf
Delay(10)
Until key
ProcedureReturn key
EndProcedure
OpenConsole()
PrintN(""):Print("Partition 'c:\' wirklich formatieren ? (j/n) ")
key = WaitKey2("jJnN") : PrintN(""):PrintN("")
If key='j' Or key='J'
Print("Formatierung.")
For a = 1 To 10
Print("."):Delay(500)
Next a
PrintN(" erfolgreich.")
Else
PrintN("Formatierung wird nicht durchgefhrt.")
EndIf
PrintN("<return>")
WaitKey2(Chr(13))
Wenn Du bei der Eingabe der Zahlen noch Backspace
unterstützen willst (zum korrigieren), dann solltest Du
Dir vielleicht ein kleines TUI dafür bauen.
Hier noch ein kleines Beispiel für die Eingabe einer maximal
6-stelligen Zahl, wobei korrigieren per Backspace erlaubt ist:
Code: Alles auswählen
Procedure.l WaitKey2(string$)
; waits until the users presses a key
; specified in string$
Repeat
asc = Asc(Inkey())
If asc > 0 And asc < 127
If FindString(string$,Chr(asc),1)
key = asc
EndIf
EndIf
Delay(10)
Until key
ProcedureReturn key
EndProcedure
OpenConsole():ClearConsole()
For a = 1 To 6: Line$+Chr(196): Next a
PrintN(Space(44)+Chr(218)+Line$+Chr(191))
PrintN("Bitte geben sie eine 6-stellige Nummer ein: "+Chr(179)+" "+Chr(179))
PrintN(Space(44)+Chr(192)+Line$+Chr(217))
ConsoleLocate(50,1)
Repeat
key = WaitKey2("0123456789"+Chr(13)+Chr(8))
If key=13 ; return
Break
ElseIf key=8 ; backspace
num$=Left(num$,Len(num$)-1)
Else
num$+Chr(key)
EndIf
ConsoleLocate(45,1)
Print(RSet(num$,6," "))
ConsoleLocate(50,1)
Until Len(num$)=6
PrintN(""):PrintN(""):PrintN("<return>")
WaitKey2(Chr(13))
Debug Val(num$)
einfach machen...