QB64.org Forum

Active Forums => Programs => Topic started by: carloscordeiro on January 31, 2021, 09:11:06 pm

Title: Mr. McNeill's extended entrance
Post by: carloscordeiro on January 31, 2021, 09:11:06 pm
Good evening Mr. SMcNeill
The Extended Entry you created is an excellent code.
I had asked bplus about it at: https://www.qb64.org/forum/index.php?topic=3209.msg124899#msg124899.

Very attentive, you showed the post.

Just now, I had time to insert a code of dozens of combinations.

In your post, you mention that the extended entry can be useful.

For me it is being very useful, I can risk saying necessary.

This code resolve the stresses that I had.
1 - exhaustion in entering 44 digits.
2 - Always running the risk of typos.
3 - the duration of registration.

Just as I ask Bplus for a lot of help.

I would very much like you to analyze if my inserted lines comply with your code.
If I made a mistake, I ask you to show me where the error is and how to fix it.

The amount of numbers entered will always be these:
010204060809111316171819202122

Carlos
Code: QB64: [Select]
  1. _TITLE "Qbasic 64"
  2. SCREEN _NEWIMAGE(600, 600, 256)
  3. _DELAY .25
  4.  
  5. 'Moldura...
  6. LINE (0, 0)-(599, 599), 11, B 'Moldura inteira
  7. LINE (1, 1)-(598, 598), 11, B
  8. LINE (2, 2)-(597, 597), 11, B
  9. LINE (3, 3)-(596, 596), 11, B
  10. LINE (4, 4)-(595, 595), 11, B
  11.  
  12. LINE (599, 43)-(2, 43), 11, B 'Linha Horizontal
  13. LINE (599, 44)-(2, 44), 11, B
  14.  
  15. 'Mostra Data
  16. d$ = MID$(DATE$, 1, 3)
  17. c$ = MID$(DATE$, 4, 3)
  18. e$ = MID$(DATE$, 7, 4)
  19. f$ = c$ + d$ + e$
  20.  
  21. COLOR 11: LOCATE 2, 28: PRINT "* * * LOTOFACIL * * *"
  22. LOCATE 2, 4: PRINT f$
  23. '--------------------------------------------------------------------------------
  24. DIM registration AS LONG
  25.  
  26.  
  27. IF _FILEEXISTS("loto.txt") THEN
  28.     OPEN "loto.txt" FOR INPUT AS #1
  29.     registration = LOF(1) \ 46
  30.     SEEK #1, LOF(1) - 45
  31.     LINE INPUT #1, nt$
  32.     CLOSE
  33.  
  34. LOCATE 25, 3: PRINT "Press [ESC] to exit."
  35. LOCATE 4, 3: PRINT "N" + CHR$(163); "mere contests =>"; registration
  36.  
  37. OPEN "loto.txt" FOR APPEND AS #1
  38.  
  39. 'PRINT ExtendedInput$
  40.  
  41.     LOCATE 6, 14: PRINT "_______________________________"
  42.     LOCATE 6, 3: PRINT "Dozens => ";
  43.     a$ = ExtendedInput$
  44.  
  45.     FOR i = 1 TO 30 STEP 2
  46.         x$ = x$ + MID$(a$, i, 2) + " "
  47.     NEXT
  48.  
  49.     x$ = _TRIM$(x$)
  50.  
  51.     LOCATE 8, 3: PRINT "Dozens => "; x$
  52.     LOCATE 10, 3: PRINT "N" + CHR$(163); "mere digits ="; LEN(x$)
  53.  
  54.     IF LEN(x$) = 44 THEN
  55.         PRINT #1, x$
  56.         LOCATE 12, 3: PRINT "Dozens successfully saved !!!"
  57.     ELSE
  58.         BEEP
  59.     END IF
  60.     x$ = ""
  61.     Scrn$ = INKEY$
  62. LOOP UNTIL Scrn$ = CHR$(27)
  63.  
  64. '--------------------------------------------------------------------------------
  65.  
  66. FUNCTION ExtendedInput$
  67.     PCOPY 0, 1
  68.     A = _AUTODISPLAY: X = POS(0): Y = CSRLIN
  69.     CP = 0: OldCP = 0 'Cursor Position
  70.     _KEYCLEAR
  71.     DO
  72.         PCOPY 1, 0
  73.         IF _KEYDOWN(100307) OR _KEYDOWN(100308) THEN AltDown = -1 ELSE AltDown = 0
  74.         k = _KEYHIT
  75.         IF AltDown THEN
  76.             SELECT CASE k 'ignore all keypresses except ALT-number presses
  77.                 CASE 48 TO 57: AltWasDown = -1: alt$ = alt$ + CHR$(k)
  78.             END SELECT
  79.         ELSE
  80.             SELECT CASE k 'without alt, add any keypresses to our input
  81.                 CASE 8
  82.                     oldin$ = in$
  83.                     IF CP > 0 THEN OldCP = CP: CP = CP - 1
  84.                     in$ = LEFT$(in$, CP) + MID$(in$, CP + 2) 'backspace to erase input
  85.                 CASE 9
  86.                     oldin$ = in$
  87.                     in$ = LEFT$(in$, CP) + SPACE$(4) + MID$(in$, CP + 1) 'four spaces for any TAB entered
  88.                     OldCP = CP
  89.                     CP = CP + 4
  90.                 CASE 32 TO 128
  91.                     IF _KEYDOWN(100305) OR _KEYDOWN(100306) THEN
  92.                         IF k = 118 OR k = 86 THEN
  93.                             oldin$ = in$
  94.                             in$ = LEFT$(in$, CP) + _CLIPBOARD$ + MID$(in$, CP + 1) 'ctrl-v paste
  95.                             'CTRL-V leaves cursor in position before the paste, without moving it after.
  96.                             'Feel free to modify that behavior here, if you want it to move to after the paste.
  97.                         END IF
  98.                         IF k = 122 OR k = 90 THEN SWAP in$, oldin$: SWAP OldCP, CP 'ctrl-z undo
  99.                     ELSE
  100.                         oldin$ = in$
  101.                         in$ = LEFT$(in$, CP) + CHR$(k) + MID$(in$, CP + 1) 'add input to our string
  102.                         OldCP = CP
  103.                         CP = CP + 1
  104.                     END IF
  105.                 CASE 18176 'Home
  106.                     CP = 0
  107.                 CASE 20224 'End
  108.                     CP = LEN(in$)
  109.                 CASE 21248 'Delete
  110.                     oldin$ = in$
  111.                     in$ = LEFT$(in$, CP) + MID$(in$, CP + 2)
  112.                 CASE 19200 'Left
  113.                     CP = CP - 1
  114.                     IF CP < 0 THEN CP = 0
  115.                 CASE 19712 'Right
  116.                     CP = CP + 1
  117.                     IF CP > LEN(in$) THEN CP = LEN(in$)
  118.             END SELECT
  119.         END IF
  120.         alt$ = RIGHT$(alt$, 3)
  121.         IF AltWasDown = -1 AND AltDown = 0 THEN
  122.             v = VAL(alt$)
  123.             IF v >= 0 AND v <= 255 THEN in$ = in$ + CHR$(v)
  124.             alt$ = "": AltWasDown = 0
  125.         END IF
  126.         blink = (blink + 1) MOD 30
  127.         LOCATE Y, X
  128.         PRINT LEFT$(in$, CP);
  129.         IF blink \ 15 THEN PRINT " "; ELSE PRINT "_";
  130.         PRINT MID$(in$, CP + 1)
  131.  
  132.         _DISPLAY
  133.         _LIMIT 30
  134.     LOOP UNTIL k = 13
  135.  
  136.     PCOPY 1, 0
  137.     LOCATE Y, X: PRINT in$
  138.     ExtendedInput$ = in$
Title: Re: Mr. McNeill's extended entrance
Post by: bplus on February 01, 2021, 12:56:56 am
Hi @carloscordeiro

I can't tell if you are asking a question or thanking Mr SMcNeill.

I would be thanking him because I copy & pasted that set of numbers from forum with Ctrl + V into the code you had and got same results as you show. That's good because I'd sure hate to type all that stuff! :) As you say, a time saver and stress relief.
Title: Re: Mr. McNeill's extended entrance
Post by: SMcNeill on February 01, 2021, 01:11:50 am
Looks to me like it’s working as intended. 

I’m happy to see it suit your needs.  Just let me know if there’s any unexpected glitches with it.  :)
Title: Re: Mr. McNeill's extended entrance
Post by: carloscordeiro on February 01, 2021, 05:01:52 pm
Hi Bplus,

I am very grateful to Mr. SMcNeill for his contributions to this forum.

thankful yet but for the excellent extended entry code.

Você sabe que serei sempre grato a todo deste forum.

I believe that I did not make my gratitude very clear, due to the question.

I'll do it more clearly.
On line 49 "a $ = ExtendedInput $".

I was unable to separate the variable "A $" from "ExtendedInput $"

That's why I asked Mr. SMcNeill to analyze if there is any error on my part.

I was not careful to explain which line was my mistake.

Thank you in advance, Mr. SMcNeill for the excellent code.

Carlos
Title: Re: Mr. McNeill's extended entrance
Post by: bplus on February 01, 2021, 05:19:19 pm
Hi Bplus,

I am very grateful to Mr. SMcNeill for his contributions to this forum.

thankful yet but for the excellent extended entry code.

Você sabe que serei sempre grato a todo deste forum.

I believe that I did not make my gratitude very clear, due to the question.

I'll do it more clearly.
On line 49 "a $ = ExtendedInput $".

I was unable to separate the variable "A $" from "ExtendedInput $"

That's why I asked Mr. SMcNeill to analyze if there is any error on my part.

I was not careful to explain which line was my mistake.

Thank you in advance, Mr. SMcNeill for the excellent code.

Carlos

So the screen shots you showed were from doing the ExtendedInput$ the hard way by hand typing all those numbers?

OK Steve may have more to add but let's cover the basic's
1. I assume you want to enter the contents of a clipboard copy and you have the number copied for a paste.
2. You have the code loaded and running.
3. You clicked that window with your code running AGAIN
      + after loading the copy to paste you click the code screen again so that screen now has the focus.
4. I may of clicked the blank line again just to be sure the paste was going where I intended
5. You pressed the Key combination Ctrl + V
6 Oh press enter just like a normal input enter, maybe that's what you are missing? need to press enter to signal when you are done inputting.
7. the paste should now magically appear?

Quote
'CTRL+V leaves cursor in position before the paste, without moving it after.

I just checked 2 more times and your code made this in loto.txt file:
Quote
01 02 04 06 08 09 11 13 16 17 18 19 20 21 22
01 02 04 06 08 09 11 13 16 17 18 19 20 21 22


EDIT: sorry I missed the last step press enter!


Title: Re: Mr. McNeill's extended entrance
Post by: carloscordeiro on February 01, 2021, 05:34:21 pm
Bplus, the code is perfect, The question I asked, it doesn't aggravate.

I just thought that I had done something wrong so that "A$" could not be separated.

Image shows what I am trying to express.

I am happy even using the semicolon.

Once again, thank you very much Mr. SMcNeill.

Carlos
Title: Re: Mr. McNeill's extended entrance
Post by: carloscordeiro on February 01, 2021, 05:50:05 pm
"I just checked 2 more times and your code made this in loto.txt file:"

"EDIT: sorry I missed the last step press enter!"


I didn't understand, Bplus
Title: Re: Mr. McNeill's extended entrance
Post by: SMcNeill on February 01, 2021, 05:54:29 pm
Quote
I'll do it more clearly.
On line 49 "a $ = ExtendedInput $".

I was unable to separate the variable "A $" from "ExtendedInput $"

I'm not entirely certain what you're asking here.  ExtendedInput is a FUNCTION, so it's going to always behave like a function.  Think of it like the math command for absolute values -- it can't just sit in your code by itself, doing nothing.

You can:

PRINT ABS(-2)

OR

X = X + ABS(-2)

But you can't just toss in a stray:

ABS(-2)



FUNCTIONS aren't stand alone commands.  They require something to interact with and to receive their value.

SUBS, on the other hand, can be stand-alone commands, like CLS, PRINT, or END. 

Since ExtendedInput is a function, it has to have a variable to send its information to, thus the A$ = ExtendedInput is required.  (Or at least some string variable is.  You can change A$ to Whatever$ if you like, and it'd suit your needs better.)

If you're looking for a way to turn A$ into A (as a number), then you'd want to take the VAL of the ExtendedInput.

A = VAL(ExtendedInput)

Though, with the way you're entering and adding spaces to the values, I really don't think that's what you're wanting to do...

Are you trying to turn that long string into an array of 15 Numbers?  If so, you'd just use VAL of the MID$, like you did on line 52 when you inserted the spaces for readability, and assign the values then to your array.

Like I say, I'm not completely certain what you're asking, or what you're trying to do.  What's the purpose in "separating the variable a$ from ExtendedInput?  What are you trying to Accomplish?



Could the solution be as simple as:

DIM A AS STRING 'Place at top of code.

A = ExtendedInput 'no need for $
Title: Re: Mr. McNeill's extended entrance
Post by: bplus on February 01, 2021, 06:03:37 pm
"I just checked 2 more times and your code made this in loto.txt file:"

"EDIT: sorry I missed the last step press enter!"


I didn't understand, Bplus

OK I copy number to clipboard.
I click the the screen with your running program.
I then press Ctrl and V at the same time
the copy of the unseparated numbers cover the blank line
I press the enter button sometimes called the return button
the blank line is back but the numbers are now 2 lines down all separated as shown in the loto.txt file.

Looks good to me, I did a couple more times and the file is loading up with copies of that separated number.
Title: Re: Mr. McNeill's extended entrance
Post by: carloscordeiro on February 01, 2021, 06:12:44 pm
As I already said, Mr. SMcNeill. I am very satisfied with your code.

I always express myself badly.

I'll try again:
This is what I did to show the cursor after "=> '
     LOCATE 6, 3: PRINT "Dozens =>";
     a $ = ExtendedInput $

I tried to do this:
  a $ = ExtendedInput $
LOCATE 6, 3: PRINT "Dozens =>"; a $
  Did not work

Now I know that ExtendedInput is a FUNCTION.

Always grateful to you.

Carlos
Title: Re: Mr. McNeill's extended entrance
Post by: bplus on February 01, 2021, 06:20:00 pm
As I already said, Mr. SMcNeill. I am very satisfied with your code.

I always express myself badly.

I'll try again:
This is what I did to make the cursor look after "=> '
     LOCATE 6, 3: PRINT "Dozens =>";
     a $ = ExtendedInput $

I tried to do this:
  a $ = ExtendedInput $
LOCATE 6, 3: PRINT "Dozens =>"; a $
  Did not work

Now I know that ExtendedInput is a FUNCTION.

Always grateful to you.

Carlos

Well you are throwing me off with the $ separated from variable or function

But if you want to see the pasted text after Ctrl V do so BEFORE you press enter, you will see it on line 6 in it's raw form before the rest of the code gets to it, separates it and then loops around and redraws the line for the next thing to input.
Title: Re: Mr. McNeill's extended entrance
Post by: carloscordeiro on February 01, 2021, 06:34:19 pm
Bplus, is the translator who is separating the $ from the variable.

I am not able to express it correctly.

But it's all right.

"It looks good to me, I did it a few more times and the file is carrying copies of that separate number."

Here's saving without a copy.

Two images so that there is no question left.

As Mr. SMcNeill said, ExtendedInput should be constantly reading ...

Carlos
Title: Re: Mr. McNeill's extended entrance
Post by: bplus on February 01, 2021, 07:31:50 pm
Quote
Curses foiled again ;(

Translation, it seems if you start typing something after you paste in the number and before you press enter, that text ends up before the pasted in number or text. That's not good. The curser should appear after the pasted in text.

Is that it Carlos? The curser is in the wrong place after the paste.
Title: Re: Mr. McNeill's extended entrance
Post by: FellippeHeitor on February 01, 2021, 07:38:28 pm
Oi, Carlos. Às vezes a gente se perde mesmo na tradução. Não sei se sua pergunta já foi respondida, mas posso te ajudar com algo? Já que falamos a mesma língua, podemos nos ser mutuamente úteis.

Abraço!
Title: Re: Mr. McNeill's extended entrance
Post by: bplus on February 01, 2021, 07:47:31 pm
Quote
Curses foiled again ;(

Translation, it seems if you start typing something after you paste in the number and before you press enter, that text ends up before the pasted in number or text. That's not good. The curser should appear after the pasted in text.

Is that it Carlos? The curser is in the wrong place after the paste.
Title: Re: Mr. McNeill's extended entrance
Post by: SMcNeill on February 01, 2021, 07:49:07 pm
What you're probably look for is more of this:


Code: [Select]

SUB ExtendedInput (prompt$, result$)
    PCOPY 0, 1
    A = _AUTODISPLAY: X = POS(0): Y = CSRLIN
    CP = 0: OldCP = 0 'Cursor Position
    _KEYCLEAR
    DO
        PCOPY 1, 0
        IF _KEYDOWN(100307) OR _KEYDOWN(100308) THEN AltDown = -1 ELSE AltDown = 0
        k = _KEYHIT
        IF AltDown THEN
            SELECT CASE k 'ignore all keypresses except ALT-number presses
                CASE 48 TO 57: AltWasDown = -1: alt$ = alt$ + CHR$(k)
            END SELECT
        ELSE
            SELECT CASE k 'without alt, add any keypresses to our input
                CASE 8
                    oldin$ = in$
                    IF CP > 0 THEN OldCP = CP: CP = CP - 1
                    in$ = LEFT$(in$, CP) + MID$(in$, CP + 2) 'backspace to erase input
                CASE 9
                    oldin$ = in$
                    in$ = LEFT$(in$, CP) + SPACE$(4) + MID$(in$, CP + 1) 'four spaces for any TAB entered
                    OldCP = CP
                    CP = CP + 4
                CASE 32 TO 128
                    IF _KEYDOWN(100305) OR _KEYDOWN(100306) THEN
                        IF k = 118 OR k = 86 THEN
                            oldin$ = in$
                            in$ = LEFT$(in$, CP) + _CLIPBOARD$ + MID$(in$, CP + 1) 'ctrl-v paste
                            'CTRL-V leaves cursor in position before the paste, without moving it after.
                            'Feel free to modify that behavior here, if you want it to move to after the paste.
                        END IF
                        IF k = 122 OR k = 90 THEN SWAP in$, oldin$: SWAP OldCP, CP 'ctrl-z undo
                    ELSE
                        oldin$ = in$
                        in$ = LEFT$(in$, CP) + CHR$(k) + MID$(in$, CP + 1) 'add input to our string
                        OldCP = CP
                        CP = CP + 1
                    END IF
                CASE 18176 'Home
                    CP = 0
                CASE 20224 'End
                    CP = LEN(in$)
                CASE 21248 'Delete
                    oldin$ = in$
                    in$ = LEFT$(in$, CP) + MID$(in$, CP + 2)
                CASE 19200 'Left
                    CP = CP - 1
                    IF CP < 0 THEN CP = 0
                CASE 19712 'Right
                    CP = CP + 1
                    IF CP > LEN(in$) THEN CP = LEN(in$)
            END SELECT
        END IF
        alt$ = RIGHT$(alt$, 3)
        IF AltWasDown = -1 AND AltDown = 0 THEN
            v = VAL(alt$)
            IF v >= 0 AND v <= 255 THEN in$ = in$ + CHR$(v)
            alt$ = "": AltWasDown = 0
        END IF
        blink = (blink + 1) MOD 30
        LOCATE Y, X
        PRINT prompt$; LEFT$(in$, CP);
        IF blink \ 15 THEN PRINT " "; ELSE PRINT "_";
        PRINT MID$(in$, CP + 1)
 
        _DISPLAY
        _LIMIT 30
    LOOP UNTIL k = 13
 
    PCOPY 1, 0
    LOCATE Y, X: PRINT prompt$, in$
    Result$ = in$
    IF A THEN _AUTODISPLAY
END FUNCTION


Tweaked on my iPad and untested, so if it doesn't work 100% on the first try, maybe someone can correct whatever my glitch might be.  If not, I'll correct it tomorrow when I'm back at the PC.  (That's IF there's a glitch at all.  I think it'll work with no issues, with these simple changes.

Usage here would then become:

LOCATE 6,3: ExtendedInput "Dozens =>", a$

It would eliminate the need for that PRINT statement and the semicolon after it.
Title: Re: Mr. McNeill's extended entrance
Post by: carloscordeiro on February 01, 2021, 08:47:59 pm
Thank you Fellippe Heitor for offering to help. But Mr. SMcNeill understood. I believe after I posted the two images.

"Translation, it looks like if you start typing something after pasting the number and before pressing enter, that text ends up being pasted into the number or text. This is not good. The cursor should appear after the pasted text."
Is that Carlos? The cursor is in the wrong place after pasting.

Bplus, I did this test, but as I only intend to insert the 30 digits, I cannot charge a code that is already meeting my needs.

Correction image that Mr. SMcNeill on line 48.

Thank you Bplus, Feliipe  and the creator of the excellent code. Mr. SMcNeill.

Thank you very much.

Carlos
Title: Re: Mr. McNeill's extended entrance
Post by: _vince on February 01, 2021, 09:15:11 pm
Nice, I remember it was the cool thing in QBasic to write your own INPUT routine for greater flexibility.  Especially for finite length strings or *s for passwords.

Here's a very old McINPUT of similar sort https://www.tapatalk.com/groups/qbasic/programlist-mac-t30409-s30.html#p64871 (https://www.tapatalk.com/groups/qbasic/programlist-mac-t30409-s30.html#p64871)

Mr. McNeill's is the gold standard for QB64
Title: Re: Mr. McNeill's extended entrance
Post by: carloscordeiro on February 01, 2021, 09:24:39 pm
I am very satisfied with the code.

But if Mr. SMcNeill considers that he should place the cursor after the pasted text.
Would be nice.
Bplus, this happens, if you type something after pasting the text.
Title: Re: Mr. McNeill's extended entrance
Post by: SMcNeill on February 01, 2021, 09:31:49 pm
CTRL-V to paste, then hit the END key to move to the end of the text.  ;)

Or, modify the code where the comment is about CTRL-V not moving the cursor.  Just add:

CP = CP + LEN(_CLIPBOARD$)
Title: Re: Mr. McNeill's extended entrance
Post by: bplus on February 01, 2021, 10:43:23 pm
Oh ha! just wanted a FUNCTION turned into a SUB. I always thought INPUT would be more correct as a FUNCTON because you expect it to return a value.

Well Steve nice try but you cant sneak in anything new with all these old traditionalists hanging about ;-))
Title: Re: Mr. McNeill's extended entrance
Post by: SMcNeill on February 01, 2021, 11:24:49 pm
Oh ha! just wanted a FUNCTION turned into a SUB. I always thought INPUT would be more correct as a FUNCTON because you expect it to return a value.

Well Steve nice try but you cant sneak in anything new with all these old traditionalists hanging about ;-))

The problem was the semicolon after the PRINT statement.  Carlos wanted a 1 line solution, rather than having it on two lines.

This was bad:
PRINT “Dozens => “;
a$ = ExtendedInput$

This is good:
ExtendedInput “Dozens => “, a$

See?  There’s no annoying, dangling semicolon at the end of the second version.

Carlos just wanted it all on a single line to suit his coding style.  ;D

(Though I do wonder why a colon wouldn’t have worked just as well?  PRINT “Dozens => “;: a$ = ExtendedInput)
Title: Re: Mr. McNeill's extended entrance
Post by: carloscordeiro on February 02, 2021, 04:38:24 pm


Quote
The problem was the semicolon after the PRINT statement.  Carlos wanted a 1 line solution, rather than having it on two lines.

This was bad:
PRINT “Dozens => “;
a$ = ExtendedInput$

This is good:
ExtendedInput “Dozens => “, a$

See?  There’s no annoying, dangling semicolon at the end of the second version.

Carlos just wanted it all on a single line to suit his coding style.  ;D

(Though I do wonder why a colon wouldn’t have worked just as well?  PRINT “Dozens => “;: a$ = ExtendedInput)


I don't want to get a bad impression here on the forum.

I just thought I was using the wrong code, because A $ as in the pictures, it erases the line LOCATE 6, 3: PRINT "Dezenas =>" aS
What made you think that, was the fact that I realized that there is no way to leave A $ alone.
I was happy to know and thanked.
I apologize for making you interpret this.

Carlos
Title: Re: Mr. McNeill's extended entrance
Post by: carloscordeiro on February 02, 2021, 05:00:03 pm
As I already said, Mr. SMcNeill. I am very satisfied with your code.

I always express myself poorly.

I'll try again:
This is what I did to show the cursor after "=> '
      LOCATE 6, 3: PRINT "Dozens =>";
      a $ = ExtendedInput $

I tried to do this:
   a $ = ExtendedInput $
LOCATE 6, 3: PRINT "Tens =>"; a $
   Did not work

Now I know that ExtendedInput is a FUNCTION.

Always grateful to you.
Title: Re: Mr. McNeill's extended entrance
Post by: bplus on February 02, 2021, 05:17:58 pm
Well now I know what language to translate from:
Title: Re: Mr. McNeill's extended entrance
Post by: carloscordeiro on February 02, 2021, 06:02:01 pm
CTRL-V to paste, then hit the END key to move to the end of the text.  ;)

Or, modify the code where the comment is about CTRL-V not moving the cursor.  Just add:

CP = CP + LEN(_CLIPBOARD$)
Ok, Bplus, I no longer wanted to disturb Mr. SMcNeill.

Do you know which line of Mr. SMcNeill's code I should add:

All right, I added line 121

CP = CP + LEN (_CLIPBOARD $)?
Well now I know what language to translate from:
Title: Re: Mr. McNeill's extended entrance
Post by: bplus on February 02, 2021, 06:35:53 pm
Quote
All right, I added line 121

Okey
Title: Re: Mr. McNeill's extended entrance
Post by: carloscordeiro on February 03, 2021, 07:20:27 pm
Quote
And, if folks need something else added to this, feel free to speak up while I'm still at home and have a few days where I don't have to take care of mom.  (Which gives you the next 3 days, or so, to make requests for additions/alterations.)

Good evening Mr. SMcNeill

I created another scenario for your code, which made me very happy.

In this scenario, I noticed that the keyboard buffer has the character “22”, in addition to the 30 tens.

He's doing the loop two laps before he stops.

It continues to ignore the line if h> 10 So stop.

Sample image and code.


Carlos
Code: QB64: [Select]
  1. _TITLE "Qbasic 64"
  2. SCREEN _NEWIMAGE(600, 600, 256)
  3. _DELAY .25
  4.  
  5.  
  6. 'PRINT ExtendedInput$
  7.  
  8. LOCATE 2, 14: PRINT "_______________________________"
  9. LOCATE 2, 3: PRINT "Dozens => ";
  10. a$ = ExtendedInput$
  11.  
  12. h = 4
  13. j = 2
  14. K$ = INKEY$
  15.     FOR e = 1 TO 100
  16.         h = h + 1
  17.         IF h > 10 THEN
  18.             COLOR 30: LOCATE 30, 3: PRINT "Press Enter to continue ..."
  19.             DO
  20.                 _LIMIT 30
  21.             LOOP UNTIL INKEY$ = CHR$(13)
  22.             h = 5: j = 25
  23.         END IF
  24.  
  25.         FOR i = 1 TO 30 STEP 2
  26.             x$ = x$ + MID$(a$, i, 2) + " "
  27.         NEXT
  28.  
  29.         x$ = _TRIM$(x$)
  30.  
  31.         _LIMIT 60
  32.  
  33.         LOCATE h, j: PRINT "test"; e; " k$ = "; K$; ASC(K$)
  34.     NEXT
  35.     Scrn$ = INKEY$
  36. LOOP UNTIL Scrn$ = CHR$(27)
  37.  
  38.  
  39. FUNCTION ExtendedInput$
  40.     PCOPY 0, 1
  41.     A = _AUTODISPLAY: X = POS(0): Y = CSRLIN
  42.     CP = 0: OldCP = 0 'Cursor Position
  43.     _KEYCLEAR
  44.     DO
  45.         PCOPY 1, 0
  46.         IF _KEYDOWN(100307) OR _KEYDOWN(100308) THEN AltDown = -1 ELSE AltDown = 0
  47.         k = _KEYHIT
  48.         IF AltDown THEN
  49.             SELECT CASE k 'ignore all keypresses except ALT-number presses
  50.                 CASE 48 TO 57: AltWasDown = -1: alt$ = alt$ + CHR$(k)
  51.             END SELECT
  52.         ELSE
  53.             SELECT CASE k 'without alt, add any keypresses to our input
  54.                 CASE 8
  55.                     oldin$ = in$
  56.                     IF CP > 0 THEN OldCP = CP: CP = CP - 1
  57.                     in$ = LEFT$(in$, CP) + MID$(in$, CP + 2) 'backspace to erase input
  58.                 CASE 9
  59.                     oldin$ = in$
  60.                     in$ = LEFT$(in$, CP) + SPACE$(4) + MID$(in$, CP + 1) 'four spaces for any TAB entered
  61.                     OldCP = CP
  62.                     CP = CP + 4
  63.                 CASE 32 TO 128
  64.                     IF _KEYDOWN(100305) OR _KEYDOWN(100306) THEN
  65.                         IF k = 118 OR k = 86 THEN
  66.                             oldin$ = in$
  67.                             in$ = LEFT$(in$, CP) + _CLIPBOARD$ + MID$(in$, CP + 1) 'ctrl-v paste
  68.                             'CTRL-V leaves cursor in position before the paste, without moving it after.
  69.                             'Feel free to modify that behavior here, if you want it to move to after the paste.
  70.                             CP = CP + LEN(_CLIPBOARD$)
  71.                         END IF
  72.                         IF k = 122 OR k = 90 THEN SWAP in$, oldin$: SWAP OldCP, CP 'ctrl-z undo
  73.                     ELSE
  74.                         oldin$ = in$
  75.                         in$ = LEFT$(in$, CP) + CHR$(k) + MID$(in$, CP + 1) 'add input to our string
  76.                         OldCP = CP
  77.                         CP = CP + 1
  78.                     END IF
  79.                 CASE 18176 'Home
  80.                     CP = 0
  81.                 CASE 20224 'End
  82.                     CP = LEN(in$)
  83.                 CASE 21248 'Delete
  84.                     oldin$ = in$
  85.                     in$ = LEFT$(in$, CP) + MID$(in$, CP + 2)
  86.                 CASE 19200 'Left
  87.                     CP = CP - 1
  88.                     IF CP < 0 THEN CP = 0
  89.                 CASE 19712 'Right
  90.                     CP = CP + 1
  91.                     IF CP > LEN(in$) THEN CP = LEN(in$)
  92.             END SELECT
  93.         END IF
  94.         alt$ = RIGHT$(alt$, 3)
  95.         IF AltWasDown = -1 AND AltDown = 0 THEN
  96.             v = VAL(alt$)
  97.             IF v >= 0 AND v <= 255 THEN in$ = in$ + CHR$(v)
  98.             alt$ = "": AltWasDown = 0
  99.         END IF
  100.         blink = (blink + 1) MOD 30
  101.         LOCATE Y, X
  102.         PRINT LEFT$(in$, CP);
  103.         IF blink \ 15 THEN PRINT " "; ELSE PRINT "_";
  104.         PRINT MID$(in$, CP + 1)
  105.  
  106.         _DISPLAY
  107.         _LIMIT 30
  108.     LOOP UNTIL k = 13
  109.  
  110.     PCOPY 1, 0
  111.     LOCATE Y, X: PRINT in$
  112.     ExtendedInput$ = in$
  113.  
  114.  
  115.  
Title: Re: Mr. McNeill's extended entrance
Post by: carloscordeiro on February 04, 2021, 06:11:22 pm
I will not give up.

I am asking for help.

Bplus if you know what is causing this ASC code (22) to appear.

It is causing the loop to take two turns before stopping.

He skip the line 78. IF h> 41 THEN stop.

Don't abandon me.

My search code, plus Mr. McNeill's extended entry code.

Dozens to test
010204080910121314151617182023

Carlos
Code: QB64: [Select]
  1. _TITLE "Qbasic 64"
  2. SCREEN _NEWIMAGE(700, 740, 256)
  3. _DELAY .25
  4.  
  5. 'Moldura...
  6. LINE (0, 0)-(699, 739), 11, B 'Moldura inteira
  7. LINE (1, 1)-(698, 738), 11, B
  8. LINE (2, 2)-(697, 737), 11, B
  9. LINE (3, 3)-(696, 736), 11, B
  10. LINE (4, 4)-(695, 735), 11, B
  11.  
  12. LINE (699, 43)-(2, 43), 11, B 'Linha Horizontal
  13. LINE (699, 44)-(2, 44), 11, B
  14.  
  15. LINE (536, 737)-(536, 44), 11, B 'Linha Vertical
  16. LINE (535, 737)-(535, 44), 11, B
  17.  
  18. 'Mostra Data
  19. d$ = MID$(DATE$, 1, 3)
  20. c$ = MID$(DATE$, 4, 3)
  21. e$ = MID$(DATE$, 7, 4)
  22. f$ = c$ + d$ + e$
  23.  
  24. COLOR 11: LOCATE 2, 35: PRINT "* * * LOTOFACIL * * *"
  25. LOCATE 2, 4: PRINT f$: COLOR 7
  26.  
  27. '------------------------------------------------------------------------
  28. DIM cor1(80) AS _INTEGER64
  29. DIM nt(1 TO 3000) AS STRING
  30. DIM pesquisa AS LONG
  31.  
  32.  
  33. OPEN "loto.txt" FOR INPUT AS #1
  34. pesquisa = LOF(1) \ 46
  35. FOR t = 1 TO pesquisa
  36.     LINE INPUT #1, nt$(t)
  37.  
  38. COLOR 15: LOCATE 4, 3: PRINT "N" + CHR$(163); "meros de concursos =>"; pesquisa
  39.  
  40.     COLOR 30
  41.     'PRINT ExtendedInput$
  42.     LOCATE 6, 14: PRINT "_______________________________"
  43.     LOCATE 6, 3: PRINT "Dezenas => ";
  44.     a$ = ExtendedInput$
  45.  
  46.     K$ = INKEY$ ' ASCII code number
  47.  
  48.     FOR i = 1 TO 30 STEP 2
  49.         x$ = x$ + MID$(a$, i, 2) + " "
  50.     NEXT
  51.     Pes$ = _TRIM$(x$)
  52.  
  53.     IF LEN(Pes$) = 44 THEN
  54.         LOCATE 8, 3: PRINT "Dezenas => "; Pes$; " ="; LEN(Pes$)
  55.         g = 0
  56.         h = 9
  57.         onze = 0
  58.         doze = 0
  59.         trez = 0
  60.         quat = 0
  61.  
  62.         'COLOR 13: LOCATE 44, 3: PRINT "Digite [ S ] para SAIR..."
  63.         ' COLOR 15
  64.         'LOCATE 44, 34: PRINT "                                 "
  65.         'LOCATE 6, 14: PRINT "____________________________________________"
  66.         ' LOCATE 6, 3: INPUT "Dezenas => ", pes$
  67.         'COLOR 13: LOCATE 44, 3: PRINT "                         "
  68.  
  69.         '---------------------------------------------------------------------------
  70.  
  71.         FOR rs = 1 TO pesquisa
  72.             IF h > 41 THEN
  73.                 COLOR 13: LOCATE 44, 34: PRINT "Pressione Enter para continuar..."
  74.                 DO
  75.                     _LIMIT 30
  76.                 LOOP UNTIL INKEY$ = CHR$(13)
  77.                 FOR S = 9 TO 43
  78.                     LOCATE S, 2: PRINT "                                                                 "
  79.                     LOCATE S, 70: PRINT "                "
  80.                 NEXT S
  81.                 h = 9
  82.             END IF
  83.             h = h + 1
  84.             x = 3
  85.             COLOR 15: LOCATE h, x: PRINT RIGHT$("0000" + LTRIM$(STR$(rs)), 4); " => "
  86.  
  87.             FOR i = 1 TO 44 STEP 3
  88.                 x = x + 3
  89.                 tt$ = MID$(nt$(rs), i, 2)
  90.                 FOR r = 1 TO LEN(Pes$) STEP 3
  91.                     O$ = MID$(Pes$, r, 2)
  92.                     IF tt$ = O$ THEN
  93.                         g = g + 1
  94.                         cor1(g) = i
  95.                         EXIT FOR
  96.                     ELSE
  97.                         COLOR 7: LOCATE h, x + 5: PRINT tt$
  98.                     END IF
  99.                 NEXT r
  100.             NEXT i
  101.  
  102.             IF g <= 10 THEN
  103.                 LOCATE h, 2: PRINT "                                                        "
  104.                 h = h - 1
  105.                 g = 0
  106.             END IF
  107.  
  108.             IF g = 11 THEN
  109.                 onze = onze + 1
  110.                 COLOR 48
  111.                 LOCATE h, x + 8: PRINT "=>";: PRINT " Onze"
  112.                 FOR ag = 1 TO 11
  113.                     LOCATE h, 10 + cor1(ag): PRINT MID$(nt$(rs), cor1(ag), 2)
  114.                 NEXT ag
  115.                 COLOR 7
  116.             END IF
  117.  
  118.             IF g = 12 THEN
  119.                 doze = doze + 1
  120.                 COLOR 52
  121.                 LOCATE h, x + 8: PRINT "=>";: PRINT " Doze"
  122.                 FOR ag = 1 TO 12
  123.                     LOCATE h, 10 + cor1(ag): PRINT MID$(nt$(rs), cor1(ag), 2)
  124.                 NEXT ag
  125.                 COLOR 7
  126.             END IF
  127.  
  128.             IF g = 13 THEN
  129.                 trez = trez + 1
  130.                 COLOR 36
  131.                 LOCATE h, x + 8: PRINT "=>";: PRINT " Treze"
  132.                 FOR ag = 1 TO 13
  133.                     LOCATE h, 10 + cor1(ag): PRINT MID$(nt$(rs), cor1(ag), 2)
  134.                 NEXT ag
  135.                 COLOR 7
  136.             END IF
  137.  
  138.             IF g = 14 THEN
  139.                 quat = quat + 1
  140.                 COLOR 40
  141.                 LOCATE h, x + 8: PRINT "=>";: PRINT " Quatorze"
  142.                 FOR ag = 1 TO 14
  143.                     LOCATE h, 10 + cor1(ag): PRINT MID$(nt$(rs), cor1(ag), 2)
  144.                 NEXT ag
  145.                 COLOR 7
  146.             END IF
  147.  
  148.             IF g = 15 THEN
  149.                 COLOR 68
  150.                 LOCATE h, x + 8: PRINT "=>";: PRINT " Quinze"
  151.                 FOR ag = 1 TO 15
  152.                     LOCATE h, 10 + cor1(ag): PRINT MID$(nt$(rs), cor1(ag), 2)
  153.                 NEXT ag
  154.                 COLOR 7
  155.             END IF
  156.  
  157.             g = 0
  158.  
  159.  
  160.             LOCATE 18, 69: PRINT "k$ ASCII code "; K$ 'ASCII code
  161.             LOCATE 20, 69: PRINT "k$ ASCII code "; ASC(K$) 'Shows ASCII code number
  162.  
  163.  
  164.             COLOR 48
  165.             LOCATE 8, 70: PRINT "N11:"; RIGHT$("000" + LTRIM$(STR$(onze)), 3); " - Vezes"
  166.             COLOR 52
  167.             LOCATE 10, 70: PRINT "N12:"; RIGHT$("000" + LTRIM$(STR$(doze)), 3); " - Vezes"
  168.             COLOR 36
  169.             LOCATE 12, 70: PRINT "N13:"; RIGHT$("000" + LTRIM$(STR$(trez)), 3); " - Vezes"
  170.             COLOR 40
  171.             LOCATE 14, 70: PRINT "N13:"; RIGHT$("000" + LTRIM$(STR$(quat)), 3); " - Vezes"
  172.         NEXT
  173.     ELSE
  174.         BEEP
  175.     END IF
  176.     x$ = ""
  177.     'Scrn$ = INKEY$
  178. LOOP UNTIL Scrn$ = CHR$(27)
  179.  
  180.  
  181. '--------------------------------------------------------------------------------
  182.  
  183. FUNCTION ExtendedInput$
  184.     PCOPY 0, 1
  185.     A = _AUTODISPLAY: X = POS(0): Y = CSRLIN
  186.     CP = 0: OldCP = 0 'Cursor Position
  187.     _KEYCLEAR
  188.     DO
  189.         PCOPY 1, 0
  190.         IF _KEYDOWN(100307) OR _KEYDOWN(100308) THEN AltDown = -1 ELSE AltDown = 0
  191.         k = _KEYHIT
  192.         IF AltDown THEN
  193.             SELECT CASE k 'ignore all keypresses except ALT-number presses
  194.                 CASE 48 TO 57: AltWasDown = -1: alt$ = alt$ + CHR$(k)
  195.             END SELECT
  196.         ELSE
  197.             SELECT CASE k 'without alt, add any keypresses to our input
  198.                 CASE 8
  199.                     oldin$ = in$
  200.                     IF CP > 0 THEN OldCP = CP: CP = CP - 1
  201.                     in$ = LEFT$(in$, CP) + MID$(in$, CP + 2) 'backspace to erase input
  202.                 CASE 9
  203.                     oldin$ = in$
  204.                     in$ = LEFT$(in$, CP) + SPACE$(4) + MID$(in$, CP + 1) 'four spaces for any TAB entered
  205.                     OldCP = CP
  206.                     CP = CP + 4
  207.                 CASE 32 TO 128
  208.                     IF _KEYDOWN(100305) OR _KEYDOWN(100306) THEN
  209.                         IF k = 118 OR k = 86 THEN
  210.                             oldin$ = in$
  211.                             in$ = LEFT$(in$, CP) + _CLIPBOARD$ + MID$(in$, CP + 1) 'ctrl-v paste
  212.                             'CTRL-V leaves cursor in position before the paste, without moving it after.
  213.                             'Feel free to modify that behavior here, if you want it to move to after the paste.
  214.                             CP = CP + LEN(_CLIPBOARD$)
  215.                         END IF
  216.                         IF k = 122 OR k = 90 THEN SWAP in$, oldin$: SWAP OldCP, CP 'ctrl-z undo
  217.                     ELSE
  218.                         oldin$ = in$
  219.                         in$ = LEFT$(in$, CP) + CHR$(k) + MID$(in$, CP + 1) 'add input to our string
  220.                         OldCP = CP
  221.                         CP = CP + 1
  222.                     END IF
  223.                 CASE 18176 'Home
  224.                     CP = 0
  225.                 CASE 20224 'End
  226.                     CP = LEN(in$)
  227.                 CASE 21248 'Delete
  228.                     oldin$ = in$
  229.                     in$ = LEFT$(in$, CP) + MID$(in$, CP + 2)
  230.                 CASE 19200 'Left
  231.                     CP = CP - 1
  232.                     IF CP < 0 THEN CP = 0
  233.                 CASE 19712 'Right
  234.                     CP = CP + 1
  235.                     IF CP > LEN(in$) THEN CP = LEN(in$)
  236.             END SELECT
  237.         END IF
  238.         alt$ = RIGHT$(alt$, 3)
  239.         IF AltWasDown = -1 AND AltDown = 0 THEN
  240.             v = VAL(alt$)
  241.             IF v >= 0 AND v <= 255 THEN in$ = in$ + CHR$(v)
  242.             alt$ = "": AltWasDown = 0
  243.         END IF
  244.         blink = (blink + 1) MOD 30
  245.         LOCATE Y, X
  246.         PRINT LEFT$(in$, CP);
  247.         IF blink \ 15 THEN PRINT " "; ELSE PRINT "_";
  248.         PRINT MID$(in$, CP + 1)
  249.  
  250.         _DISPLAY
  251.         _LIMIT 30
  252.     LOOP UNTIL k = 13
  253.  
  254.     PCOPY 1, 0
  255.     LOCATE Y, X: PRINT in$
  256.     ExtendedInput$ = in$
Title: Re: Mr. McNeill's extended entrance
Post by: bplus on February 04, 2021, 07:42:53 pm
Quote
E, se as pessoas precisarem de algo mais adicionado a isso, fique à vontade para falar enquanto ainda estou em casa e ter alguns dias sem ter que cuidar da mãe. (O que dá a você os próximos 3 dias, ou mais, para fazer solicitações de acréscimos / alterações.)

Boa noite Sr. SMcNeill

Criei outro cenário para o seu código, o que me deixou muito feliz.

Nesse cenário, notei que o buffer do teclado possui o caractere “22”, além das 30 dezenas.

Ele está fazendo o loop dar duas voltas antes de parar.

Ele continua a ignorar a linha se h> 10 Então pare.

Imagem e código de exemplo.

Carlos
Code: QB64: [Select]
  1. _TITLE "Qbasic 64"
  2. SCREEN _NEWIMAGE(600, 600, 256)
  3. _DELAY .25
  4.  
  5.  
  6. 'PRINT ExtendedInput$
  7.  
  8. LOCATE 2, 14: PRINT "_______________________________"
  9. LOCATE 2, 3: PRINT "Dozens => ";
  10. a$ = ExtendedInput$
  11.  
  12. h = 4
  13. j = 2
  14. K$ = INKEY$
  15.     FOR e = 1 TO 100
  16.         h = h + 1
  17.         IF h > 10 THEN
  18.             COLOR 30: LOCATE 30, 3: PRINT "Press Enter to continue ..."
  19.             DO
  20.                 _LIMIT 30
  21.             LOOP UNTIL INKEY$ = CHR$(13)
  22.             h = 5: j = 25
  23.         END IF
  24.  
  25.         FOR i = 1 TO 30 STEP 2
  26.             x$ = x$ + MID$(a$, i, 2) + " "
  27.         NEXT
  28.  
  29.         x$ = _TRIM$(x$)
  30.  
  31.         _LIMIT 60
  32.  
  33.         LOCATE h, j: PRINT "test"; e; " k$ = "; K$; ASC(K$)
  34.     NEXT
  35.     Scrn$ = INKEY$
  36. LOOP UNTIL Scrn$ = CHR$(27)
  37.  
  38.  
  39. FUNCTION ExtendedInput$
  40.     PCOPY 0, 1
  41.     A = _AUTODISPLAY: X = POS(0): Y = CSRLIN
  42.     CP = 0: OldCP = 0 'Cursor Position
  43.     _KEYCLEAR
  44.     DO
  45.         PCOPY 1, 0
  46.         IF _KEYDOWN(100307) OR _KEYDOWN(100308) THEN AltDown = -1 ELSE AltDown = 0
  47.         k = _KEYHIT
  48.         IF AltDown THEN
  49.             SELECT CASE k 'ignore all keypresses except ALT-number presses
  50.                 CASE 48 TO 57: AltWasDown = -1: alt$ = alt$ + CHR$(k)
  51.             END SELECT
  52.         ELSE
  53.             SELECT CASE k 'without alt, add any keypresses to our input
  54.                 CASE 8
  55.                     oldin$ = in$
  56.                     IF CP > 0 THEN OldCP = CP: CP = CP - 1
  57.                     in$ = LEFT$(in$, CP) + MID$(in$, CP + 2) 'backspace to erase input
  58.                 CASE 9
  59.                     oldin$ = in$
  60.                     in$ = LEFT$(in$, CP) + SPACE$(4) + MID$(in$, CP + 1) 'four spaces for any TAB entered
  61.                     OldCP = CP
  62.                     CP = CP + 4
  63.                 CASE 32 TO 128
  64.                     IF _KEYDOWN(100305) OR _KEYDOWN(100306) THEN
  65.                         IF k = 118 OR k = 86 THEN
  66.                             oldin$ = in$
  67.                             in$ = LEFT$(in$, CP) + _CLIPBOARD$ + MID$(in$, CP + 1) 'ctrl-v paste
  68.                             'CTRL-V leaves cursor in position before the paste, without moving it after.
  69.                             'Feel free to modify that behavior here, if you want it to move to after the paste.
  70.                             CP = CP + LEN(_CLIPBOARD$)
  71.                         END IF
  72.                         IF k = 122 OR k = 90 THEN SWAP in$, oldin$: SWAP OldCP, CP 'ctrl-z undo
  73.                     ELSE
  74.                         oldin$ = in$
  75.                         in$ = LEFT$(in$, CP) + CHR$(k) + MID$(in$, CP + 1) 'add input to our string
  76.                         OldCP = CP
  77.                         CP = CP + 1
  78.                     END IF
  79.                 CASE 18176 'Home
  80.                     CP = 0
  81.                 CASE 20224 'End
  82.                     CP = LEN(in$)
  83.                 CASE 21248 'Delete
  84.                     oldin$ = in$
  85.                     in$ = LEFT$(in$, CP) + MID$(in$, CP + 2)
  86.                 CASE 19200 'Left
  87.                     CP = CP - 1
  88.                     IF CP < 0 THEN CP = 0
  89.                 CASE 19712 'Right
  90.                     CP = CP + 1
  91.                     IF CP > LEN(in$) THEN CP = LEN(in$)
  92.             END SELECT
  93.         END IF
  94.         alt$ = RIGHT$(alt$, 3)
  95.         IF AltWasDown = -1 AND AltDown = 0 THEN
  96.             v = VAL(alt$)
  97.             IF v >= 0 AND v <= 255 THEN in$ = in$ + CHR$(v)
  98.             alt$ = "": AltWasDown = 0
  99.         END IF
  100.         blink = (blink + 1) MOD 30
  101.         LOCATE Y, X
  102.         PRINT LEFT$(in$, CP);
  103.         IF blink \ 15 THEN PRINT " "; ELSE PRINT "_";
  104.         PRINT MID$(in$, CP + 1)
  105.  
  106.         _DISPLAY
  107.         _LIMIT 30
  108.     LOOP UNTIL k = 13
  109.  
  110.     PCOPY 1, 0
  111.     LOCATE Y, X: PRINT in$
  112.     ExtendedInput$ = in$
  113.  
  114.  
  115.  


Hi Carlos,

I'm still here but this looks to me a note addressed to Steve, so I let it alone.
 


I thought you had things working or corrected with Steve's SUB version of ExtendedInput but in code from quote you are back to the earlier Function version???  That's the one takes a prompt.

Now I will review up to this post before the last and see what I can find out about this 22 thing.
Title: Re: Mr. McNeill's extended entrance
Post by: bplus on February 04, 2021, 08:10:07 pm
Here is where the 22 is coming from but I haven't a clue what you are trying to do with this new code.

Code: QB64: [Select]
  1. _TITLE "Qbasic 64"
  2. SCREEN _NEWIMAGE(600, 600, 256)
  3. _DELAY .25
  4.  
  5.  
  6. 'PRINT ExtendedInput$
  7.  
  8. LOCATE 2, 14: PRINT "_______________________________"
  9. LOCATE 2, 3: PRINT "Dozens => ";
  10. a$ = ExtendedInput$
  11.  
  12. h = 4
  13. j = 2
  14. 'K$ = INKEY$   '<<<<<<<<<<<<<<<<<<<<<<<<<< what is this for?
  15. K$ = "Ola Mundo"  ' >>>> see how it effects your code?
  16.     FOR e = 1 TO 100
  17.         h = h + 1
  18.         IF h > 10 THEN
  19.             COLOR 30: LOCATE 30, 3: PRINT "Press Enter to continue ..."
  20.             DO
  21.                 _LIMIT 30
  22.             LOOP UNTIL INKEY$ = CHR$(13)
  23.             h = 5: j = 25
  24.         END IF
  25.  
  26.         FOR i = 1 TO 30 STEP 2
  27.             x$ = x$ + MID$(a$, i, 2) + " "
  28.         NEXT
  29.  
  30.         x$ = _TRIM$(x$)
  31.  
  32.         _LIMIT 60
  33.  
  34.         LOCATE h, j: PRINT "test"; e; " k$ = "; k$; ASC(k$)
  35.     NEXT
  36.     Scrn$ = INKEY$
  37. LOOP UNTIL Scrn$ = CHR$(27)
  38.  
  39.  
  40. FUNCTION ExtendedInput$
  41.     PCOPY 0, 1
  42.     A = _AUTODISPLAY: X = POS(0): Y = CSRLIN
  43.     CP = 0: OldCP = 0 'Cursor Position
  44.     _KEYCLEAR
  45.     DO
  46.         PCOPY 1, 0
  47.         IF _KEYDOWN(100307) OR _KEYDOWN(100308) THEN AltDown = -1 ELSE AltDown = 0
  48.         k = _KEYHIT
  49.         IF AltDown THEN
  50.             SELECT CASE k 'ignore all keypresses except ALT-number presses
  51.                 CASE 48 TO 57: AltWasDown = -1: alt$ = alt$ + CHR$(k)
  52.             END SELECT
  53.         ELSE
  54.             SELECT CASE k 'without alt, add any keypresses to our input
  55.                 CASE 8
  56.                     oldin$ = in$
  57.                     IF CP > 0 THEN OldCP = CP: CP = CP - 1
  58.                     in$ = LEFT$(in$, CP) + MID$(in$, CP + 2) 'backspace to erase input
  59.                 CASE 9
  60.                     oldin$ = in$
  61.                     in$ = LEFT$(in$, CP) + SPACE$(4) + MID$(in$, CP + 1) 'four spaces for any TAB entered
  62.                     OldCP = CP
  63.                     CP = CP + 4
  64.                 CASE 32 TO 128
  65.                     IF _KEYDOWN(100305) OR _KEYDOWN(100306) THEN
  66.                         IF k = 118 OR k = 86 THEN
  67.                             oldin$ = in$
  68.                             in$ = LEFT$(in$, CP) + _CLIPBOARD$ + MID$(in$, CP + 1) 'ctrl-v paste
  69.                             'CTRL-V leaves cursor in position before the paste, without moving it after.
  70.                             'Feel free to modify that behavior here, if you want it to move to after the paste.
  71.                             CP = CP + LEN(_CLIPBOARD$)
  72.                         END IF
  73.                         IF k = 122 OR k = 90 THEN SWAP in$, oldin$: SWAP OldCP, CP 'ctrl-z undo
  74.                     ELSE
  75.                         oldin$ = in$
  76.                         in$ = LEFT$(in$, CP) + CHR$(k) + MID$(in$, CP + 1) 'add input to our string
  77.                         OldCP = CP
  78.                         CP = CP + 1
  79.                     END IF
  80.                 CASE 18176 'Home
  81.                     CP = 0
  82.                 CASE 20224 'End
  83.                     CP = LEN(in$)
  84.                 CASE 21248 'Delete
  85.                     oldin$ = in$
  86.                     in$ = LEFT$(in$, CP) + MID$(in$, CP + 2)
  87.                 CASE 19200 'Left
  88.                     CP = CP - 1
  89.                     IF CP < 0 THEN CP = 0
  90.                 CASE 19712 'Right
  91.                     CP = CP + 1
  92.                     IF CP > LEN(in$) THEN CP = LEN(in$)
  93.             END SELECT
  94.         END IF
  95.         alt$ = RIGHT$(alt$, 3)
  96.         IF AltWasDown = -1 AND AltDown = 0 THEN
  97.             v = VAL(alt$)
  98.             IF v >= 0 AND v <= 255 THEN in$ = in$ + CHR$(v)
  99.             alt$ = "": AltWasDown = 0
  100.         END IF
  101.         blink = (blink + 1) MOD 30
  102.         LOCATE Y, X
  103.         PRINT LEFT$(in$, CP);
  104.         IF blink \ 15 THEN PRINT " "; ELSE PRINT "_";
  105.         PRINT MID$(in$, CP + 1)
  106.  
  107.         _DISPLAY
  108.         _LIMIT 30
  109.     LOOP UNTIL k = 13
  110.  
  111.     PCOPY 1, 0
  112.     LOCATE Y, X: PRINT in$
  113.     ExtendedInput$ = in$
  114.  


Why aren't you printing x$ or something that makes more sense? Why the repeating K$?

What's this suppose to look like when correct?

Title: Re: Mr. McNeill's extended entrance
Post by: carloscordeiro on February 04, 2021, 09:00:27 pm
Quote
Hi Carlos,

I'm still here but this looks to me a note addressed to Steve, so I let it alone.
 .

Yes, it was addressed to Steve.
But I think I bothered him.
I didn't get an answer even though it was within the 3 days he gave.

I put the K $ to print the 22.

K $ is not part of the code

Bplus, see the complete code so as not to confuse you.

I will delete the k $. He will still skip line 78. IF h> 41 THEN stop.

The loop takes two turns before stopping.

Dezenas para testar
010204080910121314151617182023

Code: QB64: [Select]
  1. _TITLE "Qbasic 64"
  2. SCREEN _NEWIMAGE(700, 740, 256)
  3. _DELAY .25
  4.  
  5. 'Moldura...
  6. LINE (0, 0)-(699, 739), 11, B 'Moldura inteira
  7. LINE (1, 1)-(698, 738), 11, B
  8. LINE (2, 2)-(697, 737), 11, B
  9. LINE (3, 3)-(696, 736), 11, B
  10. LINE (4, 4)-(695, 735), 11, B
  11.  
  12. LINE (699, 43)-(2, 43), 11, B 'Linha Horizontal
  13. LINE (699, 44)-(2, 44), 11, B
  14.  
  15. LINE (536, 737)-(536, 44), 11, B 'Linha Vertical
  16. LINE (535, 737)-(535, 44), 11, B
  17.  
  18. 'Mostra Data
  19. d$ = MID$(DATE$, 1, 3)
  20. c$ = MID$(DATE$, 4, 3)
  21. e$ = MID$(DATE$, 7, 4)
  22. f$ = c$ + d$ + e$
  23.  
  24. COLOR 11: LOCATE 2, 35: PRINT "* * * LOTOFACIL * * *"
  25. LOCATE 2, 4: PRINT f$: COLOR 7
  26.  
  27. '------------------------------------------------------------------------
  28. DIM cor1(80) AS _INTEGER64
  29. DIM nt(1 TO 3000) AS STRING
  30. DIM pesquisa AS LONG
  31.  
  32.  
  33. OPEN "loto.txt" FOR INPUT AS #1
  34. pesquisa = LOF(1) \ 46
  35. FOR t = 1 TO pesquisa
  36.     LINE INPUT #1, nt$(t)
  37.  
  38. COLOR 15: LOCATE 4, 3: PRINT "N" + CHR$(163); "meros de concursos =>"; pesquisa
  39.  
  40.     COLOR 30
  41.     'PRINT ExtendedInput$
  42.     LOCATE 6, 14: PRINT "_______________________________"
  43.     LOCATE 6, 3: PRINT "Dezenas => ";
  44.     a$ = ExtendedInput$
  45.  
  46.     'K$ = INKEY$ ' ASCII code number
  47.  
  48.     FOR i = 1 TO 30 STEP 2
  49.         x$ = x$ + MID$(a$, i, 2) + " "
  50.     NEXT
  51.     Pes$ = _TRIM$(x$)
  52.  
  53.     IF LEN(Pes$) = 44 THEN
  54.         LOCATE 8, 3: PRINT "Dezenas => "; Pes$; " ="; LEN(Pes$)
  55.         g = 0
  56.         h = 9
  57.         onze = 0
  58.         doze = 0
  59.         trez = 0
  60.         quat = 0
  61.  
  62.         'COLOR 13: LOCATE 44, 3: PRINT "Digite [ S ] para SAIR..."
  63.         ' COLOR 15
  64.         'LOCATE 44, 34: PRINT "                                 "
  65.         'LOCATE 6, 14: PRINT "____________________________________________"
  66.         ' LOCATE 6, 3: INPUT "Dezenas => ", pes$
  67.         'COLOR 13: LOCATE 44, 3: PRINT "                         "
  68.  
  69.         '---------------------------------------------------------------------------
  70.  
  71.         FOR rs = 1 TO pesquisa
  72.             IF h > 41 THEN
  73.                 COLOR 13: LOCATE 44, 34: PRINT "Pressione Enter para continuar..."
  74.                 DO
  75.                     _LIMIT 30
  76.                 LOOP UNTIL INKEY$ = CHR$(13)
  77.                 FOR S = 9 TO 43
  78.                     LOCATE S, 2: PRINT "                                                                 "
  79.                     LOCATE S, 70: PRINT "                "
  80.                 NEXT S
  81.                 h = 9
  82.             END IF
  83.             h = h + 1
  84.             x = 3
  85.             COLOR 15: LOCATE h, x: PRINT RIGHT$("0000" + LTRIM$(STR$(rs)), 4); " => "
  86.  
  87.             FOR i = 1 TO 44 STEP 3
  88.                 x = x + 3
  89.                 tt$ = MID$(nt$(rs), i, 2)
  90.                 FOR r = 1 TO LEN(Pes$) STEP 3
  91.                     O$ = MID$(Pes$, r, 2)
  92.                     IF tt$ = O$ THEN
  93.                         g = g + 1
  94.                         cor1(g) = i
  95.                         EXIT FOR
  96.                     ELSE
  97.                         COLOR 7: LOCATE h, x + 5: PRINT tt$
  98.                     END IF
  99.                 NEXT r
  100.             NEXT i
  101.  
  102.             IF g <= 10 THEN
  103.                 LOCATE h, 2: PRINT "                                                        "
  104.                 h = h - 1
  105.                 g = 0
  106.             END IF
  107.  
  108.             IF g = 11 THEN
  109.                 onze = onze + 1
  110.                 COLOR 48
  111.                 LOCATE h, x + 8: PRINT "=>";: PRINT " Onze"
  112.                 FOR ag = 1 TO 11
  113.                     LOCATE h, 10 + cor1(ag): PRINT MID$(nt$(rs), cor1(ag), 2)
  114.                 NEXT ag
  115.                 COLOR 7
  116.             END IF
  117.  
  118.             IF g = 12 THEN
  119.                 doze = doze + 1
  120.                 COLOR 52
  121.                 LOCATE h, x + 8: PRINT "=>";: PRINT " Doze"
  122.                 FOR ag = 1 TO 12
  123.                     LOCATE h, 10 + cor1(ag): PRINT MID$(nt$(rs), cor1(ag), 2)
  124.                 NEXT ag
  125.                 COLOR 7
  126.             END IF
  127.  
  128.             IF g = 13 THEN
  129.                 trez = trez + 1
  130.                 COLOR 36
  131.                 LOCATE h, x + 8: PRINT "=>";: PRINT " Treze"
  132.                 FOR ag = 1 TO 13
  133.                     LOCATE h, 10 + cor1(ag): PRINT MID$(nt$(rs), cor1(ag), 2)
  134.                 NEXT ag
  135.                 COLOR 7
  136.             END IF
  137.  
  138.             IF g = 14 THEN
  139.                 quat = quat + 1
  140.                 COLOR 40
  141.                 LOCATE h, x + 8: PRINT "=>";: PRINT " Quatorze"
  142.                 FOR ag = 1 TO 14
  143.                     LOCATE h, 10 + cor1(ag): PRINT MID$(nt$(rs), cor1(ag), 2)
  144.                 NEXT ag
  145.                 COLOR 7
  146.             END IF
  147.  
  148.             IF g = 15 THEN
  149.                 COLOR 68
  150.                 LOCATE h, x + 8: PRINT "=>";: PRINT " Quinze"
  151.                 FOR ag = 1 TO 15
  152.                     LOCATE h, 10 + cor1(ag): PRINT MID$(nt$(rs), cor1(ag), 2)
  153.                 NEXT ag
  154.                 COLOR 7
  155.             END IF
  156.  
  157.             g = 0
  158.  
  159.  
  160.             'LOCATE 18, 69: PRINT "k$ ASCII code "; K$ 'ASCII code
  161.             ' LOCATE 20, 69: PRINT "k$ ASCII code "; ASC(K$) 'Shows ASCII code number
  162.  
  163.  
  164.             COLOR 48
  165.             LOCATE 8, 70: PRINT "N11:"; RIGHT$("000" + LTRIM$(STR$(onze)), 3); " - Vezes"
  166.             COLOR 52
  167.             LOCATE 10, 70: PRINT "N12:"; RIGHT$("000" + LTRIM$(STR$(doze)), 3); " - Vezes"
  168.             COLOR 36
  169.             LOCATE 12, 70: PRINT "N13:"; RIGHT$("000" + LTRIM$(STR$(trez)), 3); " - Vezes"
  170.             COLOR 40
  171.             LOCATE 14, 70: PRINT "N13:"; RIGHT$("000" + LTRIM$(STR$(quat)), 3); " - Vezes"
  172.         NEXT
  173.     ELSE
  174.         BEEP
  175.     END IF
  176.     x$ = ""
  177.     Scrn$ = INKEY$
  178. LOOP UNTIL Scrn$ = CHR$(27)
  179.  
  180.  
  181. '--------------------------------------------------------------------------------
  182.  
  183. FUNCTION ExtendedInput$
  184.     PCOPY 0, 1
  185.     A = _AUTODISPLAY: X = POS(0): Y = CSRLIN
  186.     CP = 0: OldCP = 0 'Cursor Position
  187.     _KEYCLEAR
  188.     DO
  189.         PCOPY 1, 0
  190.         IF _KEYDOWN(100307) OR _KEYDOWN(100308) THEN AltDown = -1 ELSE AltDown = 0
  191.         k = _KEYHIT
  192.         IF AltDown THEN
  193.             SELECT CASE k 'ignore all keypresses except ALT-number presses
  194.                 CASE 48 TO 57: AltWasDown = -1: alt$ = alt$ + CHR$(k)
  195.             END SELECT
  196.         ELSE
  197.             SELECT CASE k 'without alt, add any keypresses to our input
  198.                 CASE 8
  199.                     oldin$ = in$
  200.                     IF CP > 0 THEN OldCP = CP: CP = CP - 1
  201.                     in$ = LEFT$(in$, CP) + MID$(in$, CP + 2) 'backspace to erase input
  202.                 CASE 9
  203.                     oldin$ = in$
  204.                     in$ = LEFT$(in$, CP) + SPACE$(4) + MID$(in$, CP + 1) 'four spaces for any TAB entered
  205.                     OldCP = CP
  206.                     CP = CP + 4
  207.                 CASE 32 TO 128
  208.                     IF _KEYDOWN(100305) OR _KEYDOWN(100306) THEN
  209.                         IF k = 118 OR k = 86 THEN
  210.                             oldin$ = in$
  211.                             in$ = LEFT$(in$, CP) + _CLIPBOARD$ + MID$(in$, CP + 1) 'ctrl-v paste
  212.                             'CTRL-V leaves cursor in position before the paste, without moving it after.
  213.                             'Feel free to modify that behavior here, if you want it to move to after the paste.
  214.                             CP = CP + LEN(_CLIPBOARD$)
  215.                         END IF
  216.                         IF k = 122 OR k = 90 THEN SWAP in$, oldin$: SWAP OldCP, CP 'ctrl-z undo
  217.                     ELSE
  218.                         oldin$ = in$
  219.                         in$ = LEFT$(in$, CP) + CHR$(k) + MID$(in$, CP + 1) 'add input to our string
  220.                         OldCP = CP
  221.                         CP = CP + 1
  222.                     END IF
  223.                 CASE 18176 'Home
  224.                     CP = 0
  225.                 CASE 20224 'End
  226.                     CP = LEN(in$)
  227.                 CASE 21248 'Delete
  228.                     oldin$ = in$
  229.                     in$ = LEFT$(in$, CP) + MID$(in$, CP + 2)
  230.                 CASE 19200 'Left
  231.                     CP = CP - 1
  232.                     IF CP < 0 THEN CP = 0
  233.                 CASE 19712 'Right
  234.                     CP = CP + 1
  235.                     IF CP > LEN(in$) THEN CP = LEN(in$)
  236.             END SELECT
  237.         END IF
  238.         alt$ = RIGHT$(alt$, 3)
  239.         IF AltWasDown = -1 AND AltDown = 0 THEN
  240.             v = VAL(alt$)
  241.             IF v >= 0 AND v <= 255 THEN in$ = in$ + CHR$(v)
  242.             alt$ = "": AltWasDown = 0
  243.         END IF
  244.         blink = (blink + 1) MOD 30
  245.         LOCATE Y, X
  246.         PRINT LEFT$(in$, CP);
  247.         IF blink \ 15 THEN PRINT " "; ELSE PRINT "_";
  248.         PRINT MID$(in$, CP + 1)
  249.  
  250.         _DISPLAY
  251.         _LIMIT 30
  252.     LOOP UNTIL k = 13
  253.  
  254.     PCOPY 1, 0
  255.     LOCATE Y, X: PRINT in$
  256.     ExtendedInput$ = in$
Title: Re: Mr. McNeill's extended entrance
Post by: bplus on February 04, 2021, 09:35:14 pm
Try h > 40
Title: Re: Mr. McNeill's extended entrance
Post by: SMcNeill on February 04, 2021, 10:19:35 pm
First, and most obvious question to ask, is it a CHR$ that you’re copying when you copy the contents into the clipboard?  Check length of  _clipboard$ And only take the LEFT$(_CLIPBOARD$,desired_number_of_digits) and see if that gets rid of any stray, extra input.
Title: Re: Mr. McNeill's extended entrance
Post by: carloscordeiro on February 04, 2021, 11:08:38 pm
Quote
Verifique o comprimento do _clipboard $ E apenas pegue o LEFT $ (_ CLIPBOARD $, needed_number_of_digits) e veja se isso se livra de qualquer entrada extra perdida.
Good evening, Mr. SMcNeill.

This is exactly what may be happening

This time I'm taking great care not to confuse you.

I didn't enter my code, just leave the space for the 30 digits.

I did what you asked for, but always keep the character 22 which I don't know where it is being copied from.

 typed the 30 tens, no extra lost characters.

Only when I copy.

I followed your suggestion with an image.

010203050708091112141516212325

Thank you for responding.

Carlos

Code: QB64: [Select]
  1. _TITLE "Qbasic 64"
  2. SCREEN _NEWIMAGE(600, 600, 256)
  3. _DELAY .25
  4.  
  5. 'PRINT ExtendedInput$
  6.  
  7. LOCATE 2, 14: PRINT "_______________________________"
  8. LOCATE 2, 3: PRINT "Dozens => ";
  9. a$ = ExtendedInput$
  10.  
  11. K$ = INKEY$
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22. FUNCTION ExtendedInput$
  23.     PCOPY 0, 1
  24.     A = _AUTODISPLAY: X = POS(0): Y = CSRLIN
  25.     CP = 0: OldCP = 0 'Cursor Position
  26.     _KEYCLEAR
  27.     DO
  28.         PCOPY 1, 0
  29.         IF _KEYDOWN(100307) OR _KEYDOWN(100308) THEN AltDown = -1 ELSE AltDown = 0
  30.         k = _KEYHIT
  31.         IF AltDown THEN
  32.             SELECT CASE k 'ignore all keypresses except ALT-number presses
  33.                 CASE 48 TO 57: AltWasDown = -1: alt$ = alt$ + CHR$(k)
  34.             END SELECT
  35.         ELSE
  36.             SELECT CASE k 'without alt, add any keypresses to our input
  37.                 CASE 8
  38.                     oldin$ = in$
  39.                     IF CP > 0 THEN OldCP = CP: CP = CP - 1
  40.                     in$ = LEFT$(in$, CP) + MID$(in$, CP + 2) 'backspace to erase input
  41.                 CASE 9
  42.                     oldin$ = in$
  43.                     in$ = LEFT$(in$, CP) + SPACE$(4) + MID$(in$, CP + 1) 'four spaces for any TAB entered
  44.                     OldCP = CP
  45.                     CP = CP + 4
  46.                 CASE 32 TO 128
  47.                     IF _KEYDOWN(100305) OR _KEYDOWN(100306) THEN
  48.                         IF k = 118 OR k = 86 THEN
  49.                             oldin$ = in$
  50.                             in$ = LEFT$(in$, CP) + _CLIPBOARD$ + MID$(in$, CP + 1) 'ctrl-v paste
  51.                             'CTRL-V leaves cursor in position before the paste, without moving it after.
  52.                             'Feel free to modify that behavior here, if you want it to move to after the paste.
  53.                             CP = CP + LEN(_CLIPBOARD$)
  54.                         END IF
  55.                         IF k = 122 OR k = 90 THEN SWAP in$, oldin$: SWAP OldCP, CP 'ctrl-z undo
  56.                     ELSE
  57.                         oldin$ = in$
  58.                         in$ = LEFT$(in$, CP) + CHR$(k) + MID$(in$, CP + 1) 'add input to our string
  59.                         OldCP = CP
  60.                         CP = CP + 1
  61.                     END IF
  62.                 CASE 18176 'Home
  63.                     CP = 0
  64.                 CASE 20224 'End
  65.                     CP = LEN(in$)
  66.                 CASE 21248 'Delete
  67.                     oldin$ = in$
  68.                     in$ = LEFT$(in$, CP) + MID$(in$, CP + 2)
  69.                 CASE 19200 'Left
  70.                     CP = CP - 1
  71.                     IF CP < 0 THEN CP = 0
  72.                 CASE 19712 'Right
  73.                     CP = CP + 1
  74.                     IF CP > LEN(in$) THEN CP = LEN(in$)
  75.             END SELECT
  76.         END IF
  77.         alt$ = RIGHT$(alt$, 3)
  78.         IF AltWasDown = -1 AND AltDown = 0 THEN
  79.             v = VAL(alt$)
  80.             IF v >= 0 AND v <= 255 THEN in$ = in$ + CHR$(v)
  81.             alt$ = "": AltWasDown = 0
  82.         END IF
  83.         blink = (blink + 1) MOD 30
  84.         LOCATE Y, X
  85.         PRINT LEFT$(in$, CP);
  86.         IF blink \ 15 THEN PRINT " "; ELSE PRINT "_";
  87.         PRINT MID$(in$, CP + 1)
  88.  
  89.         _DISPLAY
  90.         _LIMIT 30
  91.     LOOP UNTIL k = 13
  92.  
  93.     PCOPY 1, 0
  94.     LOCATE Y, X: PRINT in$
  95.     ExtendedInput$ = in$
Title: Re: Mr. McNeill's extended entrance
Post by: bplus on February 04, 2021, 11:28:20 pm
Well I know where 22 is coming from :) I showed.

Why line 14 and why all the printing of K$ ?  22 is coming from INKEY$ you can clear INKEY$ if you want with _KEYCLEAR but then ASC(K$) will error.
Title: Re: Mr. McNeill's extended entrance
Post by: carloscordeiro on February 05, 2021, 05:17:58 pm
Quote
Why line 14 and why all the printing of K$ ?  22 is coming from INKEY$ you can clear INKEY$ if you want with _KEYCLEAR but then ASC(K$) will error.

The K $ impression is sybolic.

just to show the reason for the Loop to go twice.

_KEYCLEAR solved the problem of the intrusive ASCII code 22.

I didn't want to give up on Mr. SMcNeill's wonderful code.

Thanks again Bplus.

Carlos

Code: QB64: [Select]
  1. _TITLE "Qbasic 64"
  2. SCREEN _NEWIMAGE(600, 600, 256)
  3. _DELAY .25
  4.  
  5.  
  6. 'PRINT ExtendedInput$
  7.  
  8. LOCATE 2, 14: PRINT "_______________________________"
  9. LOCATE 2, 3: PRINT "Dozens => ";
  10. a$ = ExtendedInput$
  11.  
  12. _KEYCLEAR '_KEYCLEAR solved the problem of the intrusive ASCII code 22.
  13.  
  14. h = 4
  15. j = 2
  16. K$ = INKEY$
  17.     FOR e = 1 TO 100
  18.         h = h + 1
  19.         IF h > 10 THEN
  20.             COLOR 30: LOCATE 30, 3: PRINT "Press Enter to continue ..."
  21.             DO
  22.                 _LIMIT 30
  23.             LOOP UNTIL INKEY$ = CHR$(13)
  24.             h = 5: j = j + 20
  25.         END IF
  26.         FOR i = 1 TO 30 STEP 2
  27.             x$ = x$ + MID$(a$, i, 2) + " "
  28.         NEXT
  29.         x$ = _TRIM$(x$)
  30.         _LIMIT 60
  31.         LOCATE h, j: PRINT e; "_KEYCLEAR" ' ASC(K$)
  32.     NEXT
  33.     Scrn$ = INKEY$
  34. LOOP UNTIL Scrn$ = CHR$(27)
  35.  
  36.  
  37. FUNCTION ExtendedInput$
  38.     PCOPY 0, 1
  39.     A = _AUTODISPLAY: X = POS(0): Y = CSRLIN
  40.     CP = 0: OldCP = 0 'Cursor Position
  41.     _KEYCLEAR
  42.     DO
  43.         PCOPY 1, 0
  44.         IF _KEYDOWN(100307) OR _KEYDOWN(100308) THEN AltDown = -1 ELSE AltDown = 0
  45.         k = _KEYHIT
  46.         IF AltDown THEN
  47.             SELECT CASE k 'ignore all keypresses except ALT-number presses
  48.                 CASE 48 TO 57: AltWasDown = -1: alt$ = alt$ + CHR$(k)
  49.             END SELECT
  50.         ELSE
  51.             SELECT CASE k 'without alt, add any keypresses to our input
  52.                 CASE 8
  53.                     oldin$ = in$
  54.                     IF CP > 0 THEN OldCP = CP: CP = CP - 1
  55.                     in$ = LEFT$(in$, CP) + MID$(in$, CP + 2) 'backspace to erase input
  56.                 CASE 9
  57.                     oldin$ = in$
  58.                     in$ = LEFT$(in$, CP) + SPACE$(4) + MID$(in$, CP + 1) 'four spaces for any TAB entered
  59.                     OldCP = CP
  60.                     CP = CP + 4
  61.                 CASE 32 TO 128
  62.                     IF _KEYDOWN(100305) OR _KEYDOWN(100306) THEN
  63.                         IF k = 118 OR k = 86 THEN
  64.                             oldin$ = in$
  65.                             in$ = LEFT$(in$, CP) + _CLIPBOARD$ + MID$(in$, CP + 1) 'ctrl-v paste
  66.                             'CTRL-V leaves cursor in position before the paste, without moving it after.
  67.                             'Feel free to modify that behavior here, if you want it to move to after the paste.
  68.                             CP = CP + LEN(_CLIPBOARD$)
  69.                         END IF
  70.                         IF k = 122 OR k = 90 THEN SWAP in$, oldin$: SWAP OldCP, CP 'ctrl-z undo
  71.                     ELSE
  72.                         oldin$ = in$
  73.                         in$ = LEFT$(in$, CP) + CHR$(k) + MID$(in$, CP + 1) 'add input to our string
  74.                         OldCP = CP
  75.                         CP = CP + 1
  76.                     END IF
  77.                 CASE 18176 'Home
  78.                     CP = 0
  79.                 CASE 20224 'End
  80.                     CP = LEN(in$)
  81.                 CASE 21248 'Delete
  82.                     oldin$ = in$
  83.                     in$ = LEFT$(in$, CP) + MID$(in$, CP + 2)
  84.                 CASE 19200 'Left
  85.                     CP = CP - 1
  86.                     IF CP < 0 THEN CP = 0
  87.                 CASE 19712 'Right
  88.                     CP = CP + 1
  89.                     IF CP > LEN(in$) THEN CP = LEN(in$)
  90.             END SELECT
  91.         END IF
  92.         alt$ = RIGHT$(alt$, 3)
  93.         IF AltWasDown = -1 AND AltDown = 0 THEN
  94.             v = VAL(alt$)
  95.             IF v >= 0 AND v <= 255 THEN in$ = in$ + CHR$(v)
  96.             alt$ = "": AltWasDown = 0
  97.         END IF
  98.         blink = (blink + 1) MOD 30
  99.         LOCATE Y, X
  100.         PRINT LEFT$(in$, CP);
  101.         IF blink \ 15 THEN PRINT " "; ELSE PRINT "_";
  102.         PRINT MID$(in$, CP + 1)
  103.  
  104.         _DISPLAY
  105.         _LIMIT 30
  106.     LOOP UNTIL k = 13
  107.  
  108.     PCOPY 1, 0
  109.     LOCATE Y, X: PRINT in$
  110.     ExtendedInput$ = in$
Title: Re: Mr. McNeill's extended entrance
Post by: carloscordeiro on February 05, 2021, 07:43:08 pm
Quote
First, and most obvious question to ask, is it a CHR$ that you’re copying when you copy the contents into the clipboard?  Check length of  _clipboard$ And only take the LEFT$(_CLIPBOARD$,desired_number_of_digits) and see if that gets rid of any stray, extra input.

I understand now, Mr. SMcNeill.

I'm copying CHR $ from "Ctrl + V"

After searching the wiki, I found out what you meant.

According to the attached table

_KEYCLEAR solved CHR $.

however, it left me without CH $ (27) to leave.

Sc $ = INKEY $
LOOP UNTIL Sc $ = CHR $ (27) "press to exit"

As I understand it, the "LEFT $ (_ CLIPBOARD $, needed_number_of_digits)".

It would be here. "in $ = LEFT $ (in $, CP) + LEFT $ (_ CLIPBOARD $, 30) + MID $ (in $, CP + 1)"?

Mr. SMcNeill. how to eliminate CHR $ (22)?

I would very much like you to respond.

I believe I am at the limit of 3 days

Carlos
Title: Re: Mr. McNeill's extended entrance
Post by: bplus on February 05, 2021, 07:50:31 pm
Carlos man! you are pointing exactly where 22 is coming from!

That is what you press to copy / paste the clipboard!

That gets stuck in INKEY$ buffer and use _KEYCLEAR to remove it.
Title: Re: Mr. McNeill's extended entrance
Post by: carloscordeiro on February 05, 2021, 07:56:53 pm
Quote
Carlos man! you are pointing exactly where 22 is coming from!

That is what you press to copy / paste the clipboard!

That gets stuck in INKEY$ buffer and use _KEYCLEAR to remove it.

I added _KEYCLEAR Bplus,

however, that left me without CH $ (27) to leave.

Sc $ = INKEY $
LOOP UNTIL Sc $ = CHR $ (27) "press to exit"
Title: Re: Mr. McNeill's extended entrance
Post by: bplus on February 05, 2021, 07:58:30 pm
I added _KEYCLEAR Bplus,

however, that left me without CH $ (27) to leave.

Sc $ = INKEY $
LOOP UNTIL Sc $ = CHR $ (27) "press to exit"

Use
Code: QB64: [Select]
  1. Loop Until _Keydown(27)  ' then don't need INKEY$

Steve might tuck _Keyclear into his ExtendedInput Sub or Function. ;-)) or Carlos could :)
Title: Re: Mr. McNeill's extended entrance
Post by: SMcNeill on February 05, 2021, 08:11:50 pm
ExtendedInput has nothing to do with you being stuck in the loop, and neither does the CHR$(22).

That 22 is coming from you hitting CTRL-V, with INKEY$.  The ExtendedInput uses _KEYHIT exclusively and doesn't touch INKEY$ at all, so all those keypresses you type when using KEYHIT are still stored in the INKEY$ buffer -- which in this case is CHR$(22) or CTRL-V...

_KEYCLEAR clears those buffers, and eliminates that problem completely, but, as  you can see from the below, you're still stuck in an endless loop which you can't break out of:

Code: QB64: [Select]
  1. _TITLE "Qbasic 64"
  2. SCREEN _NEWIMAGE(600, 600, 256)
  3.  
  4.     FOR e = 1 TO 100
  5.         h = h + 1
  6.         IF h > 10 THEN
  7.             COLOR 30: LOCATE 30, 3: PRINT "Press Enter to continue ..."
  8.             DO
  9.                 _LIMIT 30
  10.             LOOP UNTIL INKEY$ = CHR$(13)
  11.             h = 5: j = j + 20
  12.         END IF
  13.         FOR i = 1 TO 30 STEP 2
  14.             x$ = x$ + MID$(a$, i, 2) + " "
  15.         NEXT
  16.         x$ = _TRIM$(x$)
  17.         _LIMIT 60
  18.         LOCATE h, j: PRINT e; "_KEYCLEAR" ' ASC(K$)
  19.     NEXT
  20.     Scrn$ = INKEY$
  21. LOOP UNTIL Scrn$ = CHR$(27)
  22.  
  23.  

Now the reason for this is really rather simple -- you're clearing your INKEY$ buffer here:

Code: [Select]
            DO
                _LIMIT 30
            LOOP UNTIL INKEY$ = CHR$(13)

So it's going to be impossible for that buffer to key any keypresses to read here:

Code: [Select]
    Scrn$ = INKEY$ 


Now, I don't know what you're trying to do with your example here, but that's the issue -- one INKEY$ call clearing the buffer so the other one can only read a blank nothing.

As bplus suggests, swap over to something independent to INKEY$ as your exit, or do something like this:

Code: QB64: [Select]
  1. _TITLE "Qbasic 64"
  2. SCREEN _NEWIMAGE(600, 600, 256)
  3.  
  4. j = 1
  5.     FOR e = 1 TO 100
  6.         h = h + 1
  7.         IF h > 10 THEN
  8.             COLOR 30: LOCATE 30, 3: PRINT "Press Enter to continue ..."
  9.             DO
  10.                 _LIMIT 30
  11.                 Scrn$ = INKEY$
  12.                 IF Scrn$ = CHR$(27) THEN GOTO outside_loop
  13.             LOOP UNTIL Scrn$ = CHR$(13)
  14.             h = 5: j = j + 20
  15.         END IF
  16.         FOR i = 1 TO 30 STEP 2
  17.             x$ = x$ + MID$(a$, i, 2) + " "
  18.         NEXT
  19.         x$ = _TRIM$(x$)
  20.         _LIMIT 60
  21.         LOCATE h, j: PRINT e; "_KEYCLEAR" ' ASC(K$)
  22.     NEXT
  23.     Scrn$ = INKEY$
  24. LOOP UNTIL Scrn$ = CHR$(27)
  25.  
  26. outside_loop:
  27. PRINT "I'm free!  I'm free!  I'm outta those loops!"
  28.  
Title: Re: Mr. McNeill's extended entrance
Post by: bplus on February 05, 2021, 08:15:59 pm
Steve recheck your line #24 & #25

I meant
Code: QB64: [Select]
  1. Loop Until _Keydown(27)  'you don't need INKEY$
  2.  
Title: Re: Mr. McNeill's extended entrance
Post by: carloscordeiro on February 05, 2021, 08:21:57 pm
Quote
ou Carlos poderia :)

you are very funny, Bplus

the Loop until _Keydown (27) didn't work.

The code I'm using with your extended entry code
Title: Re: Mr. McNeill's extended entrance
Post by: SMcNeill on February 05, 2021, 08:26:02 pm
you are very funny, Bplus

the Loop until _Keydown (27) didn't work.

It's not working as it can't be triggered while within the INKEY$ loop...  You have to clear the INKEY$ loop and then hit 27 in the millisecond where you're between falling into it again.

You have to put your exit condition inside that central loop, if ENTER is going to be your only way to stop that manual pause.
Title: Re: Mr. McNeill's extended entrance
Post by: carloscordeiro on February 05, 2021, 08:29:23 pm
Okay, I'll try again tomorrow.

Thank you for answering Mr. SMcNeill. Thank you Bplus.

Tomorrow I'll be back again :)

Carlos
Title: Re: Mr. McNeill's extended entrance
Post by: bplus on February 05, 2021, 09:13:52 pm
Sorry Carlos I should have checked with a run, I am not quite understanding why that change wouldn't have worked. I have to look it over again.
Title: Re: Mr. McNeill's extended entrance
Post by: SMcNeill on February 05, 2021, 09:23:23 pm
Sorry Carlos I should have checked with a run, I am not quite understanding why that change wouldn't have worked. I have to look it over again.

You dont have time between loops to press ESC, before you’re stuck in the “Waiting for ENTER” loop.  That inner loop is trapping everything.
Title: Re: Mr. McNeill's extended entrance
Post by: bplus on February 05, 2021, 09:27:53 pm
What if we stick a _Limit in there and give the CPU fan a break?

I've yet to run the dang thing! :(
Title: Re: Mr. McNeill's extended entrance
Post by: SMcNeill on February 05, 2021, 09:46:40 pm
It’s like this:


DO
    DO
         _LIMIT 30
    LOOP UNTIL INKEY$ = CHR$(13)
LOOP UNTIL _KEYDOWN(27)


You’d have to hold ESC while pressing ENTER to avoid falling directly back into that inner loop.
Title: Re: Mr. McNeill's extended entrance
Post by: bplus on February 05, 2021, 09:54:26 pm
It's rigged to do 100 repeated things before even exiting and checking the outside loop,

_Keydown works just fine AFTER 100 silly loops! (press enter 100 x's now we finally check if escape pressed!)

Try this for an inner loop of 100 times:

Code: QB64: [Select]
  1.  
  2. _Title "Qbasic 64"
  3. Screen _NewImage(600, 600, 256)
  4. _Delay .25
  5.  
  6.  
  7. 'PRINT ExtendedInput$
  8.  
  9. Locate 2, 14: Print "_______________________________"
  10. Locate 2, 3: Print "Dozens => ";
  11. a$ = ExtendedInput$
  12.  
  13. _KeyClear '_KEYCLEAR solved the problem of the intrusive ASCII code 22.
  14.  
  15. h = 4
  16. j = 2
  17. K$ = InKey$
  18.     e = 0
  19.     While _KeyDown(27) = 0
  20.         e = e + 1
  21.         If e > 100 Then Exit While
  22.         h = h + 1
  23.         If h > 10 Then
  24.             Color 30: Locate 30, 3: Print "Press Enter to continue ..."
  25.             Do
  26.                 _Limit 30
  27.             Loop Until InKey$ = Chr$(13)
  28.             h = 5: j = j + 20
  29.         End If
  30.         For i = 1 To 30 Step 2
  31.             x$ = x$ + Mid$(a$, i, 2) + " "
  32.         Next
  33.         x$ = _Trim$(x$)
  34.         _Limit 60
  35.         Locate h, j: Print e; "_KEYCLEAR" ' ASC(K$)
  36.     Wend
  37.  
  38.  
  39. Function ExtendedInput$
  40.     PCopy 0, 1
  41.     A = _AutoDisplay: X = Pos(0): Y = CsrLin
  42.     CP = 0: OldCP = 0 'Cursor Position
  43.     _KeyClear
  44.     Do
  45.         PCopy 1, 0
  46.         If _KeyDown(100307) Or _KeyDown(100308) Then AltDown = -1 Else AltDown = 0
  47.         k = _KeyHit
  48.         If AltDown Then
  49.             Select Case k 'ignore all keypresses except ALT-number presses
  50.                 Case 48 TO 57: AltWasDown = -1: alt$ = alt$ + Chr$(k)
  51.             End Select
  52.         Else
  53.             Select Case k 'without alt, add any keypresses to our input
  54.                 Case 8
  55.                     oldin$ = in$
  56.                     If CP > 0 Then OldCP = CP: CP = CP - 1
  57.                     in$ = Left$(in$, CP) + Mid$(in$, CP + 2) 'backspace to erase input
  58.                 Case 9
  59.                     oldin$ = in$
  60.                     in$ = Left$(in$, CP) + Space$(4) + Mid$(in$, CP + 1) 'four spaces for any TAB entered
  61.                     OldCP = CP
  62.                     CP = CP + 4
  63.                 Case 32 TO 128
  64.                     If _KeyDown(100305) Or _KeyDown(100306) Then
  65.                         If k = 118 Or k = 86 Then
  66.                             oldin$ = in$
  67.                             in$ = Left$(in$, CP) + _Clipboard$ + Mid$(in$, CP + 1) 'ctrl-v paste
  68.                             'CTRL-V leaves cursor in position before the paste, without moving it after.
  69.                             'Feel free to modify that behavior here, if you want it to move to after the paste.
  70.                             CP = CP + Len(_Clipboard$)
  71.                         End If
  72.                         If k = 122 Or k = 90 Then Swap in$, oldin$: Swap OldCP, CP 'ctrl-z undo
  73.                     Else
  74.                         oldin$ = in$
  75.                         in$ = Left$(in$, CP) + Chr$(k) + Mid$(in$, CP + 1) 'add input to our string
  76.                         OldCP = CP
  77.                         CP = CP + 1
  78.                     End If
  79.                 Case 18176 'Home
  80.                     CP = 0
  81.                 Case 20224 'End
  82.                     CP = Len(in$)
  83.                 Case 21248 'Delete
  84.                     oldin$ = in$
  85.                     in$ = Left$(in$, CP) + Mid$(in$, CP + 2)
  86.                 Case 19200 'Left
  87.                     CP = CP - 1
  88.                     If CP < 0 Then CP = 0
  89.                 Case 19712 'Right
  90.                     CP = CP + 1
  91.                     If CP > Len(in$) Then CP = Len(in$)
  92.             End Select
  93.         End If
  94.         alt$ = Right$(alt$, 3)
  95.         If AltWasDown = -1 And AltDown = 0 Then
  96.             v = Val(alt$)
  97.             If v >= 0 And v <= 255 Then in$ = in$ + Chr$(v)
  98.             alt$ = "": AltWasDown = 0
  99.         End If
  100.         blink = (blink + 1) Mod 30
  101.         Locate Y, X
  102.         Print Left$(in$, CP);
  103.         If blink \ 15 Then Print " "; Else Print "_";
  104.         Print Mid$(in$, CP + 1)
  105.  
  106.         _Display
  107.         _Limit 30
  108.     Loop Until k = 13
  109.  
  110.     PCopy 1, 0
  111.     Locate Y, X: Print in$
  112.     ExtendedInput$ = in$
  113.  
  114.  
Title: Re: Mr. McNeill's extended entrance
Post by: carloscordeiro on February 06, 2021, 07:01:03 pm
Mr. SMcNeill and Bplux

Since the beginning of this post, I was confused.

Asking me why chr $ (22) interferes in:

  OF
                _LIMIT 30
             LOOP UNTIL INKEY $ = CHR $ (13)

Today I found out that chr $ (22) is not the real problem with the loop going two laps before stopping.

The keyboard buffer also holds CHR $ (13).

This is what causes the loop to start, without me pressing the Enter key.

See image

Wouldn't it be better to clean only the CR $ (13)?

Quote
It's rigged to do 100 repeated things before even exiting and checking the outside loop,

_Keydown works just fine AFTER 100 silly loops! (press enter 100 x's now we finally check if escape pressed!)

Try this for an inner loop of 100 times:
Bplus, perform very well by holding the ESC key while pressing ENTER

A única solução que encontrei para limpar o buffer.

Repita o:
DO
                  _LIMIT 30
               LOOP ATÉ INKEY $ = CHR $ (13)

para limpar o CR $ (13).

Carlos
Title: Re: Mr. McNeill's extended entrance
Post by: bplus on February 06, 2021, 09:10:29 pm
Glad you have it worked out Carlos, beats me what you were up to!  :)
Title: Re: Mr. McNeill's extended entrance
Post by: NOVARSEG on February 06, 2021, 10:22:46 pm
carloscordeiro

Quote
'IF h > 41 THEN
COLOR 13: LOCATE 44, 34: PRINT "Pressione Enter para continuar..."

DO
    IF INKEY$ = "" THEN EXIT DO
LOOP

DO
    _LIMIT 30
LOOP UNTIL INKEY$ = CHR$(13)

Title: Re: Mr. McNeill's extended entrance
Post by: carloscordeiro on February 07, 2021, 05:06:34 pm
Quote
'IF h > 41 THEN
COLOR 13: LOCATE 44, 34: PRINT "Pressione Enter para continuar..."

DO
    IF INKEY$ = "" THEN EXIT DO
LOOP

DO
    _LIMIT 30
LOOP UNTIL INKEY$ = CHR$(13)

NOVARSEG so I will have to press the enter key twice. Thanks for another suggestion.

Quote
Glad you have it worked out Carlos, beats me what you were up to!  :)

I thought it would solve Bplus, not this time.

What I did was move the _KeyClear that you showed in your last example.

Dentro:

Code: QB64: [Select]
  1.     COLOR 30
  2.     'PRINT ExtendedInput$
  3.     LOCATE 6, 14: PRINT "_______________________________"
  4.     LOCATE 6, 3: PRINT "Dezenas => ";
  5.     a$ = ExtendedInput$
  6.  
  7.     ' _KEYCLEAR
  8.  
  9.     FOR i = 1 TO 30 STEP 2
  10.         x$ = x$ + MID$(a$, i, 2) + " "
  11.     NEXT

For:

Code: QB64: [Select]
  1.         FOR rs = 1 TO pesquisa
  2.             IF h > 41 THEN
  3.                 _KEYCLEAR
  4.                 COLOR 13: LOCATE 44, 34: PRINT "Pressione Enter para continuar..."
  5.                 DO
  6.                     _LIMIT 30
  7.                 LOOP UNTIL INKEY$ = CHR$(13)

So far everything is fine.

Thank you all, for all the suggestions and encouragement.

I keep learning here, in this forum.

Carlos