Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Correcting the code
#9
(10-28-2023, 06:34 AM)Chris Wrote: Thank You very much, it works, but a small correction is still needed. As I wrote earlier, after pressing only the Enter key, the H# variable cannot have the value zero (0). After entering the value zero (0) it is ok, after entering any number it is ok, but when I press only the Enter key it takes the value zero (0) and that is not good. I am asking for an amendment so that after pressing only the Enter key, the H# variable takes the value N#, i.e. H# = N#. The value of N# is calculated before the loop. If you fix it, it will be great. I removed unnecessary lines. Thank you.


H$ = "": B$ = ""
WHILE LEN(H$) < 7
        B$ = ""
    WHILE B$ = ""
        B$ = INKEY$
        _LIMIT 30
    WEND
    IF B$ = Chr$(27) THEN END
    IF B$ = "-" THEN
        IF H$ = "" THEN H$ = "-" ELSE BEEP
    ENDIF
    IF INSTR("0123456789", B$) THEN H$ = H$ + B$
  IF B$ = CHR$(13) THEN EXIT WHILE
    _LIMIT 30
WEND
H# = VAL(H$): PRINT H#

Ahhh..   I was misunderstanding how you set up the rules to begin with.  See if this isn't what you're looking for:

Code: (Select All)
Do
Print "Input the correct value, by the rules! =>";
Do
a$ = Input$(1)
Select Case a$
Case "0" To "7"
If Len(num$) < 7 Then
Print a$;: num$ = num$ + a$
Else
finished = -1 'the 7 digit sequence is to be approved automagically
End If
Case Chr$(8) 'backspace
If Len(num$) > 0 Then
L = Pos(0) - 1
num$ = Left$(num$, Len(num$) - 1)
Locate , L: Print " "; 'erase the character
Locate , L: 'move the cursor back a spot
End If
Case Chr$(13) 'enter
If Len(num$) Then finished = -1 'if less than 7 digits, enter confirms
Case Chr$(27) 'escape
System
End Select
Loop Until finished
Print
Print "Your number as entereed was: "; num$
finished = 0: num$ = "" 'reset the variables
Loop 'forever and ever and ever... or until you hit the big red X to close the program.

Note, I also added the ability to hit backspace to erase a character, in case you mess up on the entry.
Reply


Messages In This Thread
Correcting the code - by Chris - 10-27-2023, 07:19 PM
RE: Correcting the code - by bplus - 10-27-2023, 08:28 PM
RE: Correcting the code - by SMcNeill - 10-27-2023, 09:31 PM
RE: Correcting the code - by Chris - 10-28-2023, 06:34 AM
RE: Correcting the code - by SMcNeill - 10-28-2023, 01:46 PM
RE: Correcting the code - by Stuart - 10-28-2023, 10:43 AM
RE: Correcting the code - by Chris - 10-28-2023, 11:34 AM
RE: Correcting the code - by Chris - 10-28-2023, 11:49 AM
RE: Correcting the code - by bplus - 10-28-2023, 12:55 PM
RE: Correcting the code - by Chris - 10-28-2023, 02:13 PM
RE: Correcting the code - by bplus - 10-28-2023, 02:46 PM
RE: Correcting the code - by SMcNeill - 10-28-2023, 06:18 PM
RE: Correcting the code - by Chris - 10-28-2023, 07:44 PM
RE: Correcting the code - by bplus - 10-28-2023, 07:47 PM
RE: Correcting the code - by SMcNeill - 10-28-2023, 09:48 PM
RE: Correcting the code - by bplus - 10-28-2023, 07:51 PM



Users browsing this thread: 1 Guest(s)