Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Correcting the code
#3
All those GOTO statements make my teeth crunch up and hurt!  /cry!

Here, try this in a much, much, much, much simpler way:

Code: (Select All)
'The code is intended to work as follows:
'when only the Enter key is pressed, the variable (H#) cannot be set to zero.
'However, when the zero (0) key is pressed, the variable (H#) is supposed to have a zero value.
'But if the entered number is 1,2,3,4,5,6 digits, it is to be confirmed with the Enter key.
'However, the 7-digit number is to be approved automatically.
'To sum up, the entered numbers may have the following values: 0, 11, 232, 1254, 36547, 325478, 3254657.
'
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
                If Len(num$) = 1 And a$ = "0" Then finished = -1 'zero needs no confirmation
                'Is zero an unique case that resets the value to 0, no matter when it appears???
                'In other words, is "10" counted as 10, or does that 0 void it out and make it a 0 automatically?
                'The rules aren't the most specific on this point.
                'If a$ = "0" Then num$ = "0": finished = -1 'this rule makes 0 a pure "reset" value, if it's necessary
            Case Chr$(13) 'enter
                If Len(num$) > 1 Then finished = -1 'if less than 7 digits, enter confirms
        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.


Looks like a lot of code, but it's mainly just all comments.
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: 2 Guest(s)