QB64.org Forum

Active Forums => Programs => Topic started by: carloscordeiro on November 19, 2020, 06:23:06 pm

Title: Line with repeated numbers
Post by: carloscordeiro on November 19, 2020, 06:23:06 pm
Hi Bplus
I come again to ask for your help.
The subject is basically the same as always, but the purpose is different.
This time, I want to count in the numbers.txt file how many lines have the same repeated numbers.
I made a very poor code, if you don't understand I can design my purpose this time.
Here is the file and the faulty code that I tried to make.
Carlos

Code: QB64: [Select]
  1. DIM repetitions(1 TO 25) AS STRING
  2. DIM repetitions2(1 TO 25)
  3. DIM total AS LONG
  4.  
  5. OPEN "numbers.txt" FOR INPUT AS #1
  6. FOR i = 1 TO 25
  7.     LINE INPUT #1, repetitions(i)
  8.  
  9. total = 1
  10. FOR e = 1 TO 25 'Imperfect code
  11.     a$ = repetitions$(e)
  12.     FOR i = e + 1 TO 25
  13.         IF VAL(repetitions$(i)) = VAL((a$)) THEN
  14.             total = total + 1
  15.             repetitions2(e) = total
  16.         END IF
  17.     NEXT
  18.     total = 1
  19.  
  20. FOR e = 1 TO 25
  21.     IF repetitions2(e) <> 0 THEN
  22.         PRINT repetitions2(e); "  -  "; repetitions$(e) 'Imperfect code
  23.     END IF
  24.  
Title: Re: Line with repeated numbers
Post by: bplus on November 19, 2020, 07:00:14 pm
Hi @carloscordeiro

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 440, 32)
  2. REDIM fileLines(1 TO 25) AS STRING, repeats(1 TO 25), repeatLines$(1 TO 25)
  3. OPEN "numbers.txt" FOR INPUT AS #1 ' get data from file
  4. FOR i = 1 TO 25
  5.     LINE INPUT #1, fileLines(i)
  6.     PRINT i, fileLines(i) 'check the lines
  7. FOR f = 1 TO 25
  8.     FOR i = 1 TO 4 ' 4 number for each file line
  9.         n = VAL(MID$(fileLines(f), i * 3 - 2, 2))
  10.         repeats(n) = repeats(n) + 1 ' count number of occurances of this number
  11.         repeatLines$(n) = repeatLines$(n) + STR$(f) + ","
  12.     NEXT
  13. 'report repeats
  14. FOR i = 1 TO 25
  15.     LOCATE i, 30: PRINT i; " repeats:"; repeats(i); " at:"; repeatLines$(i)
  16.  
  17.  
Title: Re: Line with repeated numbers
Post by: carloscordeiro on November 19, 2020, 07:58:41 pm
Hello, bplus
Once again I am unable to express the purpose of the code.
I want him to count the entire line.
In the file number.txt, there are 2 lines with the same numbers.
Ex1: 04 05 06 07 there are two (02) repeated lines.
Ex2. 03 04 05 06 there are three (03) repeated lines.
Regardless of the position of the line, I want only the numbers of the entire line and the number of times.

I attach an image marking the lines of my code with errors, as it counts the lines in excess or duplicates those that it has already counted.

Thanking you in advance for your quick response.
Carlos
Title: Re: Line with repeated numbers
Post by: bplus on November 19, 2020, 09:05:50 pm
This?
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 440, 32)
  2. REDIM fileLines(1 TO 25) AS STRING
  3. OPEN "numbers.txt" FOR INPUT AS #1 ' get data from file
  4. FOR i = 1 TO 25
  5.     LINE INPUT #1, fileLines(i)
  6. FOR i = 1 TO 24
  7.     t = 1
  8.     FOR j = i + 1 TO 25
  9.         IF _TRIM$(fileLines(i)) = _TRIM$(fileLines(j)) AND _TRIM$(fileLines(i)) <> "" THEN
  10.             t = t + 1
  11.             fileLines(j) = ""
  12.         END IF
  13.     NEXT
  14.     IF t > 1 THEN PRINT t; " "; fileLines(i)
  15.  
  16.  
Title: Re: Line with repeated numbers
Post by: carloscordeiro on November 20, 2020, 09:09:37 am
That's right, Bplus.
I think the ease you have in finding quick solutions to my questions is agile.

Great!!!

The only return, and to thank

Thank you one more time
Carlos
Title: Re: Line with repeated numbers
Post by: carloscordeiro on July 11, 2021, 08:16:52 pm
Good night, Bplus

Before I come to ask for your help, I try very hard to resolve it on my own.

This code of yours, to separate lines with repeated numbers, served me a lot at the time you created it.
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 440, 32)
  2. REDIM fileLines(1 TO 25) AS STRING
  3. OPEN "numbers.txt" FOR INPUT AS #1 ' get data from file
  4. FOR i = 1 TO 25
  5.     LINE INPUT #1, fileLines(i)
  6. FOR i = 1 TO 24
  7.     t = 1
  8.     FOR j = i + 1 TO 25
  9.         IF _TRIM$(fileLines(i)) = _TRIM$(fileLines(j)) AND _TRIM$(fileLines(i)) <> "" THEN
  10.             t = t + 1
  11.             fileLines(j) = ""
  12.         END IF
  13.     NEXT
  14.     IF t > 1 THEN PRINT t; " "; fileLines(i)
  15.  
  16.  

used it to count repeated numbers from the attached code.

Bplus, could you modify or have another idea to count numbers that come out only once?

When I insert it in the attached code, it doesn't count the number 37 as the attached image.

Code: QB64: [Select]
  1.           For i = 1 To qu - 1 'Line with repeated numbers Bplus
  2.                t = 1
  3.                For j = i + 1 To qu
  4.                     If _Trim$(soma1(i)) = _Trim$(soma1(j)) And _Trim$(soma1(i)) <> "" Then
  5.                          t = t + 1
  6.                          soma1(j) = ""
  7.                     End If
  8.                Next
  9.  
  10.                If t > 1 Then
  11.                     Color 30
  12.                     Locate i + 10, 5
  13.                     Print "Dezena = ";
  14.                     Color 10
  15.                     Locate i + 10, 8
  16.                     Print " "; soma1(i);
  17.                     Color 30
  18.                     Locate i + 10, 12
  19.                     Print "="; t
  20.                End If
  21.           Next
  22.      Else
Put this string when running the code
083033374548

Carlos
Title: Re: Line with repeated numbers
Post by: bplus on July 11, 2021, 10:30:19 pm
@carloscordeiro

Sorry not interested in immersing into this again, since last time I built an Interpreter, fixed String Math and made nice Pool game. My head and heart is a million miles away from this.
Title: Re: Line with repeated numbers
Post by: carloscordeiro on July 12, 2021, 09:32:39 am
Quote
Sorry not interested in immersing into this again, since last time I built an Interpreter, fixed String Math and made nice Pool game. My head and heart is a million miles away from this.

All right, Bplus
I didn't know you were too busy.
A hug.
Carlos.
Title: Re: Line with repeated numbers
Post by: bplus on August 03, 2021, 11:17:41 am
@carloscordeiro

This tells if lines are repeated and how many times, so all the lines are accounted for from the file, numbers.txt:
Code: QB64: [Select]
  1. Screen _NewImage(800, 440, 32)
  2. ReDim fileLines(1 To 25) As String
  3. Open "numbers.txt" For Input As #1 ' get data from file
  4. For i = 1 To 25
  5.     Line Input #1, fl$: fileLines(i) = _Trim$(fl$)
  6. For i = 1 To 25
  7.     t = 0
  8.     For j = i + 1 To 25
  9.         If _Trim$(fileLines(i)) = fileLines(j) And Left$(fileLines(i), 7) <> "Repeat " Then
  10.             t = t + 1
  11.             fileLines(j) = "Repeat " + fileLines(i)
  12.         End If
  13.     Next
  14.     If Left$(fileLines(i), 7) <> "Repeat " Then Print fileLines(i); " repeated"; t; "times." Else Print fileLines(i)
  15.  
Title: Re: Line with repeated numbers
Post by: carloscordeiro on August 03, 2021, 05:31:23 pm
Good night, Bplus.

That's what I wasn't seeing.

A small change on line 8 from 24 to 25.
FOR i = 1 TO 24

FOR i = 1 TO 24
    t = 1
    FOR j = i + 1 TO 25

For

FOR i = 1 TO 25
    t = 0
    FOR j = i + 1 TO 25

That's what you did and I didn't see it.

Bplus, around here, things are very complicated.

So I created this code with your help, I mean, almost every line of code was with your help and willingness to respond.

I'm trying to find a pattern in the numbers.

More already realized that there is not.

I was trying to help luck when I sometimes make a bet.
Title: Re: Line with repeated numbers
Post by: carloscordeiro on August 03, 2021, 05:53:51 pm
Before thanking,

I would like to ask if there is color in Qbasic 64 as in the example below.

Code: QB64: [Select]
  1. [Color 30
  2. Print "qbasic"
  3. Print "Bplus"]

The names keep flashing.

I searched the wiki and I didn't find anything

I always use:

_Title "Qbasic 64"
Screen _NewImage(700, 740, 256)
_Delay .25
_ScreenMove 20, 30

The _Newlmage screen seems to disable this old qbsic effect.

As always, thank you in advance.

Carlos
Title: Re: Line with repeated numbers
Post by: carloscordeiro on August 03, 2021, 06:12:55 pm
 line 8 from 24 to 25.
FOR i = 1 TO 24

FOR i = 1 TO 24
    t = 1
    FOR j = i + 1 TO 25

For

FOR i = 1 TO 25
    t = 0
    FOR j = i + 1 TO 25

The t=0 I left as the previous one
t=1

Title: Re: Line with repeated numbers
Post by: bplus on August 03, 2021, 07:15:41 pm
Before thanking,

I would like to ask if there is color in Qbasic 64 as in the example below.

Code: QB64: [Select]
  1. [Color 30
  2. Print "qbasic"
  3. Print "Bplus"]

The names keep flashing.

I searched the wiki and I didn't find anything

I always use:

_Title "Qbasic 64"
Screen _NewImage(700, 740, 256)
_Delay .25
_ScreenMove 20, 30

The _Newlmage screen seems to disable this old qbsic effect.

As always, thank you in advance.

Carlos

Blinking colors and other weird stuff with _NEWIMAGE  0 color setting (or default screen 0):
Code: QB64: [Select]
  1. Screen _NewImage(80, 30, 0) ' oh! using 0 means char cells not pixels in _newimage command!
  2. For i = 0 To 15
  3.     Color i, 0
  4.     Locate i + 1, 1: Print "This is color"; i; "for line"; i + 1; "."
  5.     Color i + 16
  6.     Locate i + 1, 40: Print "This is color"; i + 16; "for line"; i + 1; "."
  7.  
  8.  
 
Title: Re: Line with repeated numbers
Post by: carloscordeiro on August 03, 2021, 09:41:44 pm
Okay, Bplus

I thought that with the settings I use, I could do the same

I wanted for a kind of alert.

Thanks again.

Carlos
Title: Re: Line with repeated numbers
Post by: bplus on August 04, 2021, 12:36:24 pm
Wouldn't be hard to setup blinking text label for graphics screen.

Here's an old one:
Code: QB64: [Select]
  1. _Title "Blinking and more with text string" 'b+ 2020-02-15
  2.  
  3. '===================================================================================
  4. ' Lets blink between colors white and blue, expanding and shrinking text for 10 secs
  5. '===================================================================================
  6.  
  7. s$ = "Blink colors white and blue, expanding and shrinking centered text for 10 secs"
  8. Screen _NewImage(800, 600, 32)
  9. th = 16 'Text Height - start normal
  10. dh = 1 'change height
  11. flashTimes = 100 'with limit 10 this will take 10 times a second and be done in 100/10 secs
  12. start$ = Time$
  13. While _KeyDown(27) = 0
  14.     Cls
  15.     Print start$; ", ";
  16.     If flashTimes Then
  17.         If toggle = 1 Then C~& = &HFFFFFFFF Else C~& = &HFF0000FF
  18.         cText _Width / 2, _Height / 2, th, C~&, s$
  19.         toggle = 1 - toggle
  20.         th = th + dh
  21.         If th > 64 Then th = 64: dh = -dh
  22.         If th < 6 Then th = 6: dh = -dh
  23.         flashTimes = flashTimes - 1
  24.         lastFlash$ = Time$
  25.     Else
  26.         cText _Width / 2, _Height / 2, 16, &HFFFFFF00, s$
  27.     End If
  28.     Print lastFlash$; " <<<< notice these numbers are not flashing even though we CLS every frame"
  29.     _Display '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> eliminates blinking screens when use CLS
  30.     _Limit 10 '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>  allows maximum number of loops of 10 per sec
  31.  
  32. 'center the text at x, y with given height and color
  33. Sub cText (x, y, textHeight, K As _Unsigned Long, txt$)
  34.     Dim fg As _Unsigned Long, cur&, I&, mult, xlen
  35.     fg = _DefaultColor
  36.     'screen snapshot
  37.     cur& = _Dest
  38.     I& = _NewImage(8 * Len(txt$), 16, 32)
  39.     _Dest I&
  40.     Color K, _RGBA32(0, 0, 0, 0)
  41.     _PrintString (0, 0), txt$
  42.     mult = textHeight / 16
  43.     xlen = Len(txt$) * 8 * mult
  44.     _PutImage (x - .5 * xlen, y - .5 * textHeight)-Step(xlen, textHeight), I&, cur&
  45.     Color fg
  46.     _FreeImage I&
  47.  

Another one:
Code: QB64: [Select]
  1. Screen _NewImage(220, 50, 32)
  2. Const H$ = "Hello World"
  3. Dim Shared r&, g&, b&, old&, new&
  4. update
  5. While _KeyDown(27) = 0
  6.     If Rnd < 1 / 20 And m = 10 Then update
  7.     Cls
  8.     m = (m + 1) Mod 11
  9.     If m = 0 Then Swap old&, new&
  10.     x = 65 + m * 8
  11.     Color old&
  12.     _PrintString (65, 15), Mid$(H$, 1, m)
  13.     Color new&
  14.     _PrintString (x, 15), Mid$(H$, m + 1)
  15.     _Display
  16.     _Limit 30
  17.  
  18. Sub update
  19.     r& = Rnd * 255: g& = Rnd * 255: b& = Rnd * 255
  20.     old& = _RGB32(r&, g&, b&)
  21.     new& = _RGB32((r& + 128) Mod 255, (g& + 128) Mod 255, (b& + 128) Mod 255)
  22.  
  23.  
Title: Re: Line with repeated numbers
Post by: bplus on August 04, 2021, 01:00:27 pm
Heres one from today:
Code: QB64: [Select]
  1. _Title "BlinkingScreenLabel Sub" ' b+ 2021-08-04  for Carlos
  2.  
  3. 'just put the sub call in the loop you use to display the screen it will blink according to limit
  4.     For i = 1 To 15
  5.         BlinkingScreenLabel 1, i, "This is line" + Str$(i), i, 0
  6.     Next
  7.     _Limit 1
  8.  
  9. Sub BlinkingScreenLabel (x, y, txt$, c1~&, c2~&)
  10.     Static blink
  11.     blink = 1 - blink
  12.     saveFore~& = _DefaultColor
  13.     If blink Then Color c1~& Else Color c2~&
  14.     _PrintString (x, y), txt$
  15.     Color saveFore~& 'restore color
  16.  
Title: Re: Line with repeated numbers
Post by: carloscordeiro on August 04, 2021, 05:55:44 pm
Bplus

Below is an image of the alert that I intended to insert, to make the code more elegant.

As there is no simple way to do this.

I'll leave it as it is.

I want you to know, that when you answer my weird questions.

You make me so happy.

Thank you from the heart.

Carlos

Code: QB64: [Select]
  1. [/_Title "Qbasic 64" ' Many lines, created with help friend Bplus
  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 "* * * Mega Sena * * *"
  22. Locate 2, 4: Print f$
  23. '--------------------------------------------------------------------------------
  24. Dim nt(0 To 3000) As String
  25. Dim cadastro As Long
  26.  
  27.  
  28. If _FileExists("mega.txt") Then
  29.      Open "mega.txt" For Input As #1
  30.      cadastro = LOF(1) \ 19
  31.      For t = 1 To cadastro
  32.           Line Input #1, nt$(t)
  33.      Next
  34.      Close
  35.      Open "mega.txt" For Append As #1
  36.      Open "mega.txt" For Output As #1
  37.      done = 1
  38.  
  39.      Color 30
  40.      Locate 12, 3: Print "Concurso =>"; cadastro; "= "; nt$(cadastro)
  41.      Locate 30, 3: Print "Pressione [ESC] para sair."
  42.      Locate 4, 3: Print "N" + Chr$(163); "meros de concursos =>"; cadastro
  43.  
  44.      Locate 6, 14: Print "_____________"
  45.      Locate 6, 3: Print "Dezenas => ";
  46.      a$ = ExtendedInput$ 'code Mr. SMcNeill
  47.  
  48.      For r = 6 To 30
  49.           Locate r, 2: Print Spc(72)
  50.      Next
  51.  
  52.      For i = 1 To 12 Step 2
  53.           x$ = x$ + Mid$(a$, i, 2) + " "
  54.      Next
  55.  
  56.      x$ = _Trim$(x$)
  57.  
  58.      For i = 1 To cadastro
  59.           If x$ = nt$(i) Then
  60.                done = 0
  61.                Color 48
  62.                Locate 15, 25: Print "Contest:"; i; "exists!!!! "
  63.                Locate 17, 29: Print ; nt$(i);
  64.                Locate 18, 29: Print "================="
  65.                Color 30
  66.                Beep
  67.                Exit For
  68.           End If
  69.      Next
  70.  
  71.      Locate 8, 3: Print "Dezenas => "; x$
  72.      Locate 10, 3: Print "N£meros de digitos ="; Len(a$)
  73.  
  74.  
  75.      If Len(a$) = 12 And done = 1 Then
  76.           Print #1, x$
  77.           Color 48
  78.           Locate 15, 24: Print "Dezenas salvas com sucesso!!!"
  79.           Locate 16, 24: Print "============================="
  80.           Locate 18, 30: Print x$
  81.           Locate 19, 30: Print "================="
  82.           cadastro = cadastro + 1
  83.           nt$(cadastro) = x$
  84.           nt$ = x$
  85.           Beep
  86.      ElseIf Len(a$) > 12 Then
  87.           Color 48
  88.           Locate 20, 23: Print "Number of digits greater than 12 =>"; Len(a$)
  89.           Locate 22, 30: Print ; a$
  90.           Locate 23, 31: Print "============="
  91.           Color 30
  92.           Beep
  93.      End If
  94.  
  95.      x$ = ""
  96.      Scrn$ = InKey$
  97. Loop Until Scrn$ = Chr$(27)
  98.  
  99. Play "o3l32ceff+g"
  100. Play "mfo4l64ceg>c"
  101.  
  102. OE20 = _LoadFont("century.ttf", 82)
  103. _Font OE20
  104. Color 11 ' &H200000FF
  105. Locate 4, 90: Print " QBasic 64 "
  106. Locate 5, 90: Print " -------------- "
  107.  
  108. '--------------------------------------------------------------------------------
  109.  
  110. Function ExtendedInput$ 'code Mr. SMcNeill
  111.      PCopy 0, 1
  112.      A = _AutoDisplay: X = Pos(0): Y = CsrLin
  113.      CP = 0: OldCP = 0 'Cursor Position
  114.      _KeyClear
  115.      Do
  116.           PCopy 1, 0
  117.           If _KeyDown(100307) Or _KeyDown(100308) Then AltDown = -1 Else AltDown = 0
  118.           k = _KeyHit
  119.           If AltDown Then
  120.                Select Case k 'ignore all keypresses except ALT-number presses
  121.                     Case 48 TO 57: AltWasDown = -1: alt$ = alt$ + Chr$(k)
  122.                End Select
  123.           Else
  124.                Select Case k 'without alt, add any keypresses to our input
  125.                     Case 8
  126.                          oldin$ = in$
  127.                          If CP > 0 Then OldCP = CP: CP = CP - 1
  128.                          in$ = Left$(in$, CP) + Mid$(in$, CP + 2) 'backspace to erase input
  129.                     Case 9
  130.                          oldin$ = in$
  131.                          in$ = Left$(in$, CP) + Space$(4) + Mid$(in$, CP + 1) 'four spaces for any TAB entered
  132.                          OldCP = CP
  133.                          CP = CP + 4
  134.                     Case 32 TO 128
  135.                          If _KeyDown(100305) Or _KeyDown(100306) Then
  136.                               If k = 118 Or k = 86 Then
  137.                                    oldin$ = in$
  138.                                    in$ = Left$(in$, CP) + _Clipboard$ + Mid$(in$, CP + 1) 'ctrl-v paste
  139.                                    'CTRL-V leaves cursor in position before the paste, without moving it after.
  140.                                    'Feel free to modify that behavior here, if you want it to move to after the paste.
  141.                                    CP = CP + Len(_Clipboard$)
  142.                               End If
  143.                               If k = 122 Or k = 90 Then Swap in$, oldin$: Swap OldCP, CP 'ctrl-z undo
  144.                          Else
  145.                               oldin$ = in$
  146.                               in$ = Left$(in$, CP) + Chr$(k) + Mid$(in$, CP + 1) 'add input to our string
  147.                               OldCP = CP
  148.                               CP = CP + 1
  149.                          End If
  150.                     Case 18176 'Home
  151.                          CP = 0
  152.                     Case 20224 'End
  153.                          CP = Len(in$)
  154.                     Case 21248 'Delete
  155.                          oldin$ = in$
  156.                          in$ = Left$(in$, CP) + Mid$(in$, CP + 2)
  157.                     Case 19200 'Left
  158.                          CP = CP - 1
  159.                          If CP < 0 Then CP = 0
  160.                     Case 19712 'Right
  161.                          CP = CP + 1
  162.                          If CP > Len(in$) Then CP = Len(in$)
  163.                End Select
  164.           End If
  165.           alt$ = Right$(alt$, 3)
  166.           If AltWasDown = -1 And AltDown = 0 Then
  167.                v = Val(alt$)
  168.                If v >= 0 And v <= 255 Then in$ = in$ + Chr$(v)
  169.                alt$ = "": AltWasDown = 0
  170.           End If
  171.           blink = (blink + 1) Mod 30
  172.           Locate Y, X
  173.           Print Left$(in$, CP);
  174.           If blink \ 15 Then Print " "; Else Print "_";
  175.           Print Mid$(in$, CP + 1)
  176.  
  177.           _Display
  178.           _Limit 30
  179.      Loop Until k = 13
  180.  
  181.      PCopy 1, 0
  182.      Locate Y, X: Print in$
  183.      ExtendedInput$ = in$
  184.      If A Then _AutoDisplay
  185. ]
Title: Re: Line with repeated numbers
Post by: carloscordeiro on August 04, 2021, 06:13:23 pm
Bplus, I'm going to overdo the questions a bit.

Would you have an idea, to reduce the number of for next and if, in this other code?

You don't need to create other code, only if you have a better idea than mine.

Carlos
Code: QB64: [Select]
  1. _Title "Qbasic 64" ' Many lines, created with help friend Bplus
  2. Screen _NewImage(700, 740, 256)
  3. _Delay .25
  4.  
  5. 'Moldura...
  6. Line (0, 0)-(699, 719), 11, B 'Moldura inteira
  7. Line (1, 1)-(698, 718), 11, B
  8. Line (2, 2)-(697, 717), 11, B
  9. Line (3, 3)-(696, 716), 11, B
  10. Line (4, 4)-(695, 715), 11, B
  11.  
  12. Line (699, 43)-(2, 43), 11, B 'Linha Horizontal
  13. Line (699, 44)-(2, 44), 11, B
  14.  
  15. Line (336, 716)-(336, 44), 11, B 'Linha Vertical
  16. Line (335, 716)-(335, 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, 34: Print "* * * Mega Sena * * *"
  25. Locate 2, 4: Print f$: Color 7
  26.  
  27. '------------------------------------------------------------------------
  28. Dim nt(1 To 3000) As String
  29. Dim soma1(1 To 500) As String
  30. Dim soma2(1 To 500) As String
  31. Dim cor1(80) As _Integer64
  32. Dim seq(500) As _Integer64
  33. 'Dim re As _Integer64
  34. Dim file(1 To 50) As String
  35. '------------------------------------------------------------------------
  36.  
  37. Open "mega.txt" For Input As #1
  38. total = LOF(1) \ 19
  39. For t = 1 To total
  40.      Line Input #1, nt$(t)
  41.  
  42.  
  43. Color 30: Locate 4, 3: Print "N" + Chr$(163); "meros de concursos =>"; total
  44.      g = 0
  45.      h = 3
  46.      qu = 0
  47.      te = 0
  48.      Color 30
  49.      Locate 6, 14: Print "_____________"
  50.      Locate 6, 3: Print "Dezenas => ";
  51.      a$ = ExtendedInput$ 'code Mr. SMcNeill
  52.  
  53.      For i = 1 To 12 Step 2
  54.           x$ = x$ + Mid$(a$, i, 2) + " "
  55.      Next
  56.      Pes$ = _Trim$(x$)
  57.      If Len(Pes$) = 17 Then
  58.  
  59.           For S = 4 To 44
  60.                Locate S, 44: Print Spc(40)
  61.           Next S
  62.  
  63.           Color 78
  64.           Locate 8, 3: Print "Dezenas => "; Pes$; " ="; Len(Pes$)
  65.           Locate 9, 14: Print "================="
  66.  
  67.           For re = 1 To total
  68.                If h > 41 Then
  69.                     _KeyClear
  70.                     Color 13: Locate 44, 44: Print "Pressione Enter para continuar..."
  71.                     Color 7
  72.                     Do
  73.                          _Limit 30
  74.                     Loop Until InKey$ = Chr$(13)
  75.                     For S = 4 To 44
  76.                          Locate S, 44: Print Spc(40)
  77.                     Next S
  78.                     h = 3
  79.                End If
  80.  
  81.                h = h + 1
  82.                x = 49
  83.  
  84.                Color 15: Locate h, x - 5: Print Right$("0000" + LTrim$(Str$(re)), 4); " => "
  85.  
  86.                For i = 1 To 17 Step 3
  87.                     x = x + 3
  88.                     For r = 1 To 17 Step 3
  89.                          If Mid$(nt$(re), i, 2) = Mid$(Pes$, r, 2) Then
  90.                               g = g + 1
  91.                               cor1(g) = i
  92.                               Exit For
  93.                          Else
  94.                               Color 7: Locate h, x: Print Mid$(nt$(re), i, 2)
  95.                          End If
  96.                     Next r
  97.                Next i
  98.  
  99.                If g <= 2 Then
  100.                     Locate h, 44: Print Spc(29)
  101.                     h = h - 1
  102.                End If
  103.  
  104.                If g = 3 Then
  105.                     Color 12
  106.                     Locate h, x + 3: Print "=>";: Print " TERNO"
  107.                     For ag = 1 To 3
  108.                          te = te + 1
  109.                          Locate h, 51 + cor1(ag): Print Mid$(nt$(re), cor1(ag), 2)
  110.                          soma2(te) = Mid$(nt$(re), cor1(ag), 2)
  111.                     Next ag
  112.                     Color 7
  113.                End If
  114.  
  115.                If g = 4 Then
  116.                     Color 10
  117.                     Locate h, x + 3: Print "=>";: Print " QUADRA"
  118.                     For ag = 1 To 4
  119.                          qu = qu + 1
  120.                          Locate h, 51 + cor1(ag): Print Mid$(nt$(re), cor1(ag), 2)
  121.                          soma1$(qu) = Mid$(nt$(re), cor1(ag), 2)
  122.                     Next ag
  123.                     Color 7
  124.                End If
  125.  
  126.                If g = 5 Then
  127.                     Color 3
  128.                     Locate h, x + 3: Print "=>";: Print " QUINA"
  129.                     For ag = 1 To 5
  130.                          Locate h, 51 + cor1(ag): Print Mid$(nt$(re), cor1(ag), 2)
  131.                     Next ag
  132.                     Color 7
  133.                End If
  134.  
  135.                If g = 6 Then
  136.                     Color 14
  137.                     Locate h, x + 3:: Print "=>";: Print " SENA "
  138.                     For ag = 1 To 6
  139.                          Locate h, 51 + cor1(ag): Print Mid$(nt$(re), cor1(ag), 2)
  140.                     Next ag
  141.                     Color 7
  142.                End If
  143.                g = 0
  144.           Next
  145.           a = 12
  146.           For e = 10 To 22
  147.                Locate e, 2: Print Spc(35)
  148.           Next
  149.           '-------------------------------------------------------------------
  150.           For i = 1 To qu '- 1
  151.                t = 1
  152.                For j = i + 1 To qu
  153.                     If _Trim$(soma1(i)) = _Trim$(soma1(j)) And _Trim$(soma1(i)) <> "" Then
  154.                          t = t + 1
  155.                          soma1(j) = ""
  156.                     End If
  157.                Next
  158.                seq(i) = t
  159.                If soma1(i) <> "" Then
  160.                     a = a + 1
  161.                     Color 30
  162.                     Locate a, 3
  163.                     Print "Dez = ";
  164.                     Color 10
  165.                     Locate a, 8
  166.                     Print " "; soma1(i);
  167.                     Color 30
  168.                     Locate a, 12
  169.                     Print "="; seq(i)
  170.                End If
  171.           Next
  172.           '---------------------------------------------------------------------
  173.           a = 12
  174.           For i = 1 To te '- 1
  175.                t = 1
  176.                For j = i + 1 To te
  177.                     If _Trim$(soma2(i)) = _Trim$(soma2(j)) And _Trim$(soma2(i)) <> "" Then
  178.                          t = t + 1
  179.                          soma2(j) = ""
  180.                     End If
  181.                Next
  182.                seq(i) = t
  183.                If soma2(i) <> "" Then
  184.                     a = a + 1
  185.                     Color 30
  186.                     Locate a, 23
  187.                     Print "Dez = ";
  188.                     Color 12
  189.                     Locate a, 28
  190.                     Print " "; soma2(i);
  191.                     Color 30
  192.                     Locate a, 32
  193.                     Print "="; seq(i)
  194.                End If
  195.           Next
  196.           '-----------------------------------------------------------------------
  197.  
  198.      Else
  199.           Beep
  200.      End If
  201.      Color 13: Locate 44, 58: Print "Pressione [ESC] para sair..."
  202.      x$ = ""
  203.      Scrn$ = InKey$
  204. Loop Until Scrn$ = Chr$(27)
  205.  
  206. Play "o3l32ceff+g"
  207. Play "mfo4l64ceg>c"
  208.  
  209. OE20 = _LoadFont("century.ttf", 82)
  210. _Font OE20
  211. Color 11 ' &H200000FF
  212. Locate 4, 125: Print " QBasic 64 "
  213. Locate 5, 125: Print " -------------- "
  214.  
  215. '-------------------------------------------------------------------------------------
  216. Function ExtendedInput$ ' Mr. McNeill's extended entrance
  217.      PCopy 0, 1
  218.      A = _AutoDisplay: X = Pos(0): Y = CsrLin
  219.      CP = 0: OldCP = 0 'Cursor Position
  220.      _KeyClear
  221.      Do
  222.           PCopy 1, 0
  223.           If _KeyDown(100307) Or _KeyDown(100308) Then AltDown = -1 Else AltDown = 0
  224.           k = _KeyHit
  225.           If AltDown Then
  226.                Select Case k 'ignore all keypresses except ALT-number presses
  227.                     Case 48 TO 57: AltWasDown = -1: alt$ = alt$ + Chr$(k)
  228.                End Select
  229.           Else
  230.                Select Case k 'without alt, add any keypresses to our input
  231.                     Case 8
  232.                          oldin$ = in$
  233.                          If CP > 0 Then OldCP = CP: CP = CP - 1
  234.                          in$ = Left$(in$, CP) + Mid$(in$, CP + 2) 'backspace to erase input
  235.                     Case 9
  236.                          oldin$ = in$
  237.                          in$ = Left$(in$, CP) + Space$(4) + Mid$(in$, CP + 1) 'four spaces for any TAB entered
  238.                          OldCP = CP
  239.                          CP = CP + 4
  240.                     Case 32 TO 128
  241.                          If _KeyDown(100305) Or _KeyDown(100306) Then
  242.                               If k = 118 Or k = 86 Then
  243.                                    oldin$ = in$
  244.                                    in$ = Left$(in$, CP) + _Clipboard$ + Mid$(in$, CP + 1) 'ctrl-v paste
  245.                                    'CTRL-V leaves cursor in position before the paste, without moving it after.
  246.                                    'Feel free to modify that behavior here, if you want it to move to after the paste.
  247.                                    CP = CP + Len(_Clipboard$)
  248.                               End If
  249.                               If k = 122 Or k = 90 Then Swap in$, oldin$: Swap OldCP, CP 'ctrl-z undo
  250.                          Else
  251.                               oldin$ = in$
  252.                               in$ = Left$(in$, CP) + Chr$(k) + Mid$(in$, CP + 1) 'add input to our string
  253.                               OldCP = CP
  254.                               CP = CP + 1
  255.                          End If
  256.                     Case 18176 'Home
  257.                          CP = 0
  258.                     Case 20224 'End
  259.                          CP = Len(in$)
  260.                     Case 21248 'Delete
  261.                          oldin$ = in$
  262.                          in$ = Left$(in$, CP) + Mid$(in$, CP + 2)
  263.                     Case 19200 'Left
  264.                          CP = CP - 1
  265.                          If CP < 0 Then CP = 0
  266.                     Case 19712 'Right
  267.                          CP = CP + 1
  268.                          If CP > Len(in$) Then CP = Len(in$)
  269.                End Select
  270.           End If
  271.           alt$ = Right$(alt$, 3)
  272.           If AltWasDown = -1 And AltDown = 0 Then
  273.                v = Val(alt$)
  274.                If v >= 0 And v <= 255 Then in$ = in$ + Chr$(v)
  275.                alt$ = "": AltWasDown = 0
  276.           End If
  277.           blink = (blink + 1) Mod 30
  278.           Locate Y, X
  279.           Print Left$(in$, CP);
  280.           If blink \ 15 Then Print " "; Else Print "_";
  281.           Print Mid$(in$, CP + 1)
  282.  
  283.           _Display
  284.           _Limit 30
  285.      Loop Until k = 13
  286.  
  287.      PCopy 1, 0
  288.      Locate Y, X: Print in$
  289.      ExtendedInput$ = in$
  290.      If A Then _AutoDisplay
  291.  
  292.  

A lot for next and if

Code: QB64: [Select]
  1.                If g <= 2 Then
  2.                     Locate h, 44: Print Spc(29)
  3.                     h = h - 1
  4.                End If
  5.  
  6.                If g = 3 Then
  7.                     Color 12
  8.                     Locate h, x + 3: Print "=>";: Print " TERNO"
  9.                     For ag = 1 To 3
  10.                          te = te + 1
  11.                          Locate h, 51 + cor1(ag): Print Mid$(nt$(re), cor1(ag), 2)
  12.                          soma2(te) = Mid$(nt$(re), cor1(ag), 2)
  13.                     Next ag
  14.                     Color 7
  15.                End If
  16.  
  17.                If g = 4 Then
  18.                     Color 10
  19.                     Locate h, x + 3: Print "=>";: Print " QUADRA"
  20.                     For ag = 1 To 4
  21.                          qu = qu + 1
  22.                          Locate h, 51 + cor1(ag): Print Mid$(nt$(re), cor1(ag), 2)
  23.                          soma1$(qu) = Mid$(nt$(re), cor1(ag), 2)
  24.                     Next ag
  25.                     Color 7
  26.                End If
  27.  
  28.                If g = 5 Then
  29.                     Color 3
  30.                     Locate h, x + 3: Print "=>";: Print " QUINA"
  31.                     For ag = 1 To 5
  32.                          Locate h, 51 + cor1(ag): Print Mid$(nt$(re), cor1(ag), 2)
  33.                     Next ag
  34.                     Color 7
  35.                End If
  36.  
  37.                If g = 6 Then
  38.                     Color 14
  39.                     Locate h, x + 3:: Print "=>";: Print " SENA "
  40.                     For ag = 1 To 6
  41.                          Locate h, 51 + cor1(ag): Print Mid$(nt$(re), cor1(ag), 2)
  42.                     Next ag
  43.                     Color 7
  44.                End If
  45.                g = 0
  46.           Next

Title: Re: Line with repeated numbers
Post by: bplus on August 04, 2021, 06:26:17 pm
Hi Carlos,

Looks OK to me, but I don't really know what it's all about. If you had many more g's I would suggest using Select Case or ElseIf ... Then and loose some End If lines but right now you are in gray area where there is no big difference.

Your screen layouts look nice :)
Title: Re: Line with repeated numbers
Post by: carloscordeiro on August 04, 2021, 07:06:16 pm
Quote
Your screen layouts look nice :)

Thanks for the compliment

This code is for querying the "mega.txt" database how many times there are 3 numbers, 4 numbers and 5 numbers.

He does just that.

Would using Select Case or ElseIf improve the code?

Would it decrease a little of the "if and for next"?

Insert this sequence in the code: 041112444557

http://loterias.caixa.gov.br/wps/portal/loterias/landing/megasena/

Site where I feed the txt database