Author Topic: Mr. McNeill's extended entrance  (Read 11435 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Mr. McNeill's extended entrance
« Reply #15 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.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline carloscordeiro

  • Forum Regular
  • Posts: 102
    • View Profile
Re: Mr. McNeill's extended entrance
« Reply #16 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
Excelente_01.jpg
* Excelente_01.jpg (Filesize: 132.43 KB, Dimensions: 821x747, Views: 198)
Excelente_02.jpg
* Excelente_02.jpg (Filesize: 155.97 KB, Dimensions: 801x925, Views: 204)
« Last Edit: February 01, 2021, 09:06:23 pm by carloscordeiro »

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: Mr. McNeill's extended entrance
« Reply #17 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

Mr. McNeill's is the gold standard for QB64

Offline carloscordeiro

  • Forum Regular
  • Posts: 102
    • View Profile
Re: Mr. McNeill's extended entrance
« Reply #18 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.
wrong paste.jpg
* wrong paste.jpg (Filesize: 183.88 KB, Dimensions: 726x371, Views: 156)

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Mr. McNeill's extended entrance
« Reply #19 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$)
« Last Edit: February 01, 2021, 09:34:37 pm by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Mr. McNeill's extended entrance
« Reply #20 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 ;-))

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Mr. McNeill's extended entrance
« Reply #21 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)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline carloscordeiro

  • Forum Regular
  • Posts: 102
    • View Profile
Re: Mr. McNeill's extended entrance
« Reply #22 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
« Last Edit: February 07, 2021, 04:20:11 pm by carloscordeiro »

Offline carloscordeiro

  • Forum Regular
  • Posts: 102
    • View Profile
Re: Mr. McNeill's extended entrance
« Reply #23 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.
« Last Edit: February 07, 2021, 04:21:09 pm by carloscordeiro »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Mr. McNeill's extended entrance
« Reply #24 on: February 02, 2021, 05:17:58 pm »
Well now I know what language to translate from:
Portuguese (Brazil).PNG
* Portuguese (Brazil).PNG (Filesize: 66.6 KB, Dimensions: 658x618, Views: 146)

Offline carloscordeiro

  • Forum Regular
  • Posts: 102
    • View Profile
Re: Mr. McNeill's extended entrance
« Reply #25 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:
Ok.jpg
* Ok.jpg (Filesize: 158.45 KB, Dimensions: 974x723, Views: 142)
« Last Edit: February 02, 2021, 06:19:35 pm by carloscordeiro »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Mr. McNeill's extended entrance
« Reply #26 on: February 02, 2021, 06:35:53 pm »
Quote
All right, I added line 121

Okey

Offline carloscordeiro

  • Forum Regular
  • Posts: 102
    • View Profile
Re: Mr. McNeill's extended entrance
« Reply #27 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.  
character 22.jpg
* character 22.jpg (Filesize: 166.22 KB, Dimensions: 1009x911, Views: 134)
* Another scenario.txt (Filesize: 3.79 KB, Downloads: 100)
« Last Edit: February 07, 2021, 04:31:16 pm by carloscordeiro »

Offline carloscordeiro

  • Forum Regular
  • Posts: 102
    • View Profile
Re: Mr. McNeill's extended entrance
« Reply #28 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$
ASCLL code 22.jpg
* ASCLL code 22.jpg (Filesize: 427.22 KB, Dimensions: 1143x991, Views: 118)
* Lotofacil V2.txt (Filesize: 8.67 KB, Downloads: 94)
* loto.txt (Filesize: 96.49 KB, Downloads: 88)
« Last Edit: February 04, 2021, 06:13:36 pm by carloscordeiro »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Mr. McNeill's extended entrance
« Reply #29 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.
 
Carlos Note to Steve.PNG


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.
« Last Edit: February 04, 2021, 07:55:14 pm by bplus »