Posts: 42
Threads: 6
Joined: Sep 2022
Reputation:
0
Hello
Please modify the code.
Normal inputs are: zero (inclusive) to 6
How to convert the code so that the option without entering digits after pressing the Enter key, T # takes the value 7.
Thank You
PRINT "Enter a digit"
K$ = "": F$ = ""
WHILE LEN(K$) < 1 AND F$ <> CHR$(13)
F$ = ""
WHILE F$ = "": F$ = INKEY$: _LIMIT 30: WEND
IF F$ = CHR$(27) THEN 15
IF F$ = CHR$(32) THEN 20
IF F$ <> CHR$(13) THEN K$ = K$ + F$
WEND
T# = VAL(K$): PRINT T#
Posts: 276
Threads: 14
Joined: Apr 2022
Reputation:
27
Where are 15 & 20? The IDE is looking for line labels to go to, otherwise it throws an error.
DO: LOOP: DO: LOOP
sha_na_na_na_na_na_na_na_na_na:
Posts: 276
Threads: 14
Joined: Apr 2022
Reputation:
27
11-06-2022, 12:55 PM
(This post was last modified: 11-06-2022, 01:07 PM by OldMoses.)
If I'm understanding the problem correctly, this should achieve the desired effect.
Code: (Select All)
PRINT "Enter a digit"
K$ = "": F$ = ""
DO
F$ = INKEY$
IF F$ <> "" THEN
IF F$ = CHR$(13) THEN
F$ = "7"
ELSE
IF INSTR("0123456", F$) THEN F$ = MID$("0123456", INSTR("0123456", F$), 1) ELSE F$ = ""
END IF
K$ = K$ + F$
END IF
_LIMIT 30
LOOP UNTIL LEN(F$) <> 0
T# = VAL(K$): PRINT T#
and if you need the escape and spacebar options...
Code: (Select All)
PRINT "Enter a digit"
K$ = "": F$ = ""
DO
F$ = INKEY$
IF F$ <> "" THEN
IF F$ = CHR$(13) THEN
F$ = "7"
ELSEIF F$ = CHR$(27) THEN
GOTO escape
ELSEIF F$ = CHR$(32) THEN
GOTO spacebar
ELSE
IF INSTR("0123456", F$) THEN F$ = MID$("0123456", INSTR("0123456", F$), 1) ELSE F$ = ""
END IF
K$ = K$ + F$
END IF
_LIMIT 30
LOOP UNTIL LEN(F$) <> 0
T# = VAL(K$): PRINT T#
END
escape:
'do whatever escape is supposed to do
spacebar:
'do whatever the spacebar is supposed to do
DO: LOOP: DO: LOOP
sha_na_na_na_na_na_na_na_na_na:
Posts: 2,701
Threads: 328
Joined: Apr 2022
Reputation:
217
11-06-2022, 12:59 PM
(This post was last modified: 11-06-2022, 12:59 PM by SMcNeill.)
PRINT "Enter a digit"
DO
K$ = INPUT$(1)
LOOP UNTIL K$ >= "0" AND K$ <= "6"
PRINT K$
Posts: 42
Threads: 6
Joined: Sep 2022
Reputation:
0
Thank you very much. That's what I meant, it works as it should.
Posts: 276
Threads: 14
Joined: Apr 2022
Reputation:
27
(11-06-2022, 12:59 PM)SMcNeill Wrote: PRINT "Enter a digit"
DO
K$ = INPUT$(1)
LOOP UNTIL K$ >= "0" AND K$ <= "6"
PRINT K$
Ooooh, INPUT$, I never noticed that one before. A pretty new bauble to play with.
DO: LOOP: DO: LOOP
sha_na_na_na_na_na_na_na_na_na:
Posts: 383
Threads: 56
Joined: Apr 2022
Reputation:
13
I'm with Old Moses - that Input is one I'm not familiar with. Has it been around a long time? Is there a reason why it only deals with string values (ie Input(4) would/might be useful for non string values). I have a lot of data stored in numeric values, does Input$ automatically convert the values to strings or do they need to be stored as string values to work with Input$. It's amazing how rich QB64pe language is getting.