Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Correcting the code
#11
Quote: SMcNeill
Your code doesn't work.
I repeat once again the rules that must be met.

1. If I enter the value zero (0) and confirm with the Enter key, the H# variable should have the value zero (H# = 0)
2. If I enter numbers in the range 1-999999 and confirm with the Enter key, such values should be included in the H# variable.
3. If I enter a 7-digit number, it should be entered automatically without using the Enter key.
4. If I press ONLY the Enter key, the variable should take the value of the variable N#. So H# = N#

My predecessors may not have understood exactly what I meant.
You are experts in this field, so there should be no problem with such a short code

Good thing I already have the whole thing fixed, reply #8!
https://qb64phoenix.com/forum/showthread...0#pid21010

Don't know why above link fails continuously???
@Chris I repeat post #8
Code: (Select All)
H$ = "": B$ = ""
While Len(H$) < 7
    Locate 1, 1: Print Spc(8)
    Locate 1, 1: Print H$
    B$ = ""
    While B$ = ""
        B$ = InKey$
        _Limit 30
    Wend
    If B$ = Chr$(27) Then
        End
    ElseIf B$ = "-" Then
        If H$ = "" Then H$ = "-" Else Beep
    ElseIf InStr("0123456789", B$) Then
        H$ = H$ + B$
    ElseIf B$ = Chr$(13) And H$ = "" Then
        Beep
    ElseIf B$ = Chr$(13) And H$ <> "" Then
        Exit While
    End If
    _Limit 30
Wend
H! = Val(H$): Print "H ="; H!
b = b + ...
Reply
#12
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$
            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 Or Len(num$) = 7
    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.

So here's a question:  What happens if someone hits 00123?   Does that count as 123?  Is it valid?  Or is it 0?  Is the 0 *only* valid when by itself?  Or can it be preceeding other numbers?   What you're wanting isn't hard to do.  Figuring out the RULES of what's acceptable and what isn't, is what's hard to account for in this case.  LOL!

What happens with?  0<enter>   --- this is 0.  Correct?
00123<enter>  -- is this valid, or should that 123 automatically erase those leading zeros to make 123?  Or should it stay 00123?
0123456 -- does this count as a 7 digit value?  Or should this be 6, with that zero not possible?
Reply
#13
For example:
N# <= calculated before the loop

 0000050 ENTER => 50
  000050 ENTER => 50
  00050 ENTER => 50
    0050 ENTER => 50
      050 ENTER => 50
       50 ENTER => 50
0000000 ENTER => 0
  000000 ENTER => 0
   00000 ENTER => 0
     0000 ENTER => 0
      000 ENTER => 0
        00 ENTER => 0
          0 ENTER => 0
0000123 ENTER => 123
 000123 ENTER => 123
   00123 ENTER => 123
    0123 ENTER => 123
     123 ENTER => 123
        ENTER => N#

When the ENTER key is pressed, it is supposed to take the value calculated before the loop. Then H# = N#
There is probably also a possibility, which I have not written about before, that if you press the zero (0) key, there will be an automatic exit from the loop. There is no point in entering zeros (0) before significant figures. If someone hits zero (0), you know that nothing will happen further. But this is an additional option.

<bplus> is close to solving it but for some unknown reason it doesn't want to finish the job. And I respect that.
My code works fine, I just wanted to improve it. If this is a big problem, the topic can be closed.
Reply
#14
Quote:2. If I enter numbers in the range 1-999999 and confirm with the Enter key, such values should be included in the H# variable.

@SMcneill I like the backspace but what is wrong with 8's and 9's LOL do you think this is octal digits?

@Chris and for you sir or mam, # is the double type for floating point numbers you might like ! for long integer types, maybe even ~! to exclude negative numbers?
b = b + ...
Reply
#15
Quote:<bplus> is close to solving it but for some unknown reason it doesn't want to finish the job. And I respect that.
My code works fine, I just wanted to improve it. If this is a big problem, the topic can be closed.

Are you talking about Stuart's faulty mod of my code or are you talking about my reply #8 which I think not only finishes the job but also allows negative numbers PLUS uses the proper Type for Integers AND does it all under one IF Block of code (though it did not do backspace which it should).
b = b + ...
Reply
#16
(10-28-2023, 07:47 PM)bplus Wrote:
Quote:2. If I enter numbers in the range 1-999999 and confirm with the Enter key, such values should be included in the H# variable.

@SMcneill I like the backspace but what is wrong with 8's and 9's LOL do you think this is octal digits?

@Chris and for you sir or mam, # is the double type for floating point numbers you might like ! for long integer types, maybe even ~! to exclude negative numbers?

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.



I dunno. Reading the above, there was massive talk of 1, 2, 3, 4, 5, 6, and 7, and then my eyes skipped over the 8 in the 325478 example, so yeah... I was kinda working off an octal-base. LOL!

Change the SELECT CASE from "0" TO "7", to "0" TO "9", and it should be okay to go. That's a simple enough debig that anyone should be able to catch/fix it. Big Grin

Too many long nights here, with eyes blurring over ancient, esoteric code from the 1970s for me in this last week. My comprehension seems to be only about 30% of normal right now. I needs massive sleeps and even more massive coffees after, to get back on track! LOL!
Reply




Users browsing this thread: 9 Guest(s)