_Title "Qbasic 64" ' Many lines, created with help friend Bplus
Screen _NewImage(700, 740, 256)
_Delay .25
_ScreenMove 20, 30

'Moldura...
Line (0, 0)-(699, 719), 11, B 'Moldura inteira
Line (1, 1)-(698, 718), 11, B
Line (2, 2)-(697, 717), 11, B
Line (3, 3)-(696, 716), 11, B
Line (4, 4)-(695, 715), 11, B

Line (699, 43)-(2, 43), 11, B 'Linha Horizontal
Line (699, 44)-(2, 44), 11, B

Line (336, 716)-(336, 44), 11, B 'Linha Vertical
Line (335, 716)-(335, 44), 11, B

'Mostra Data
d$ = Mid$(Date$, 1, 3)
c$ = Mid$(Date$, 4, 3)
e$ = Mid$(Date$, 7, 4)
f$ = c$ + d$ + e$

Color 11: Locate 2, 34: Print "* * * Mega Sena * * *"
Locate 2, 77: Print Time$
Locate 2, 4: Print f$: Color 7

'------------------------------------------------------------------------
Dim nt(1 To 3000) As String
Dim soma1(1 To 500) As String
Dim soma2(1 To 500) As String
Dim cor1(80) As _Integer64
Dim seq(500) As _Integer64
'Dim re As _Integer64
Dim file(1 To 50) As String
'------------------------------------------------------------------------

Open "mega.txt" For Input As #1
total = LOF(1) \ 19
For t = 1 To total
     Line Input #1, nt$(t)
Next
Close

_ControlChr Off

Color 30: Locate 4, 3: Print "N" + Chr$(163); "meros de concursos =>"; total
Do
     g = 0
     h = 3
     qu = 0
     te = 0
     Color 30
     Locate 6, 14: Print "_____________"
     Locate 6, 3: Print "Dezenas => ";
     a$ = ExtendedInput$ 'code Mr. SMcNeill

     For i = 1 To 12 Step 2
          x$ = x$ + Mid$(a$, i, 2) + " "
     Next
     Pes$ = _Trim$(x$)
     If Len(Pes$) = 17 Then

          For S = 4 To 44
               Locate S, 44: Print Spc(40)
          Next S

          Color 78
          Locate 8, 3: Print "Dezenas => "; Pes$; " ="; Len(Pes$)
          Locate 9, 14: Print "================="

          For re = 1 To total
               If h > 41 Then
                    _KeyClear
                    Color 13: Locate 44, 44: Print "Pressione Enter para continuar..."
                    Color 7
                    Do
                         _Limit 30
                    Loop Until InKey$ = Chr$(13)
                    For S = 4 To 44
                         Locate S, 44: Print Spc(40)
                    Next S
                    h = 3
               End If

               h = h + 1
               x = 49

               Color 15: Locate h, x - 5: Print Right$("0000" + LTrim$(Str$(re)), 4); " => "

               For i = 1 To 17 Step 3
                    x = x + 3
                    For r = 1 To 17 Step 3
                         If Mid$(nt$(re), i, 2) = Mid$(Pes$, r, 2) Then
                              g = g + 1
                              cor1(g) = i
                              Exit For
                         Else
                              Color 7: Locate h, x: Print Mid$(nt$(re), i, 2)
                         End If
                    Next r
               Next i

               If g <= 2 Then
                    Locate h, 44: Print Spc(29)
                    h = h - 1
               End If

               If g = 3 Then
                    Color 12
                    Locate h, x + 3: Print "=>";: Print " TERNO"
                    For ag = 1 To 3
                         te = te + 1
                         Locate h, 51 + cor1(ag): Print Mid$(nt$(re), cor1(ag), 2)
                         soma2(te) = Mid$(nt$(re), cor1(ag), 2)
                    Next ag
                    Color 7
               End If

               If g = 4 Then
                    Color 10
                    Locate h, x + 3: Print "=>";: Print " QUADRA"
                    For ag = 1 To 4
                         qu = qu + 1
                         Locate h, 51 + cor1(ag): Print Mid$(nt$(re), cor1(ag), 2)
                         soma1$(qu) = Mid$(nt$(re), cor1(ag), 2)
                    Next ag
                    Color 7
               End If

               If g = 5 Then
                    Color 3
                    Locate h, x + 3: Print "=>";: Print " QUINA"
                    For ag = 1 To 5
                         Locate h, 51 + cor1(ag): Print Mid$(nt$(re), cor1(ag), 2)
                    Next ag
                    Color 7
               End If

               If g = 6 Then
                    Color 14
                    Locate h, x + 3:: Print "=>";: Print " SENA "
                    For ag = 1 To 6
                         Locate h, 51 + cor1(ag): Print Mid$(nt$(re), cor1(ag), 2)
                    Next ag
                    Color 7
               End If
               g = 0
          Next
          a = 12
          For e = 10 To 22
               Locate e, 2: Print Spc(35)
          Next
          '-------------------------------------------------------------------
          For i = 1 To qu '- 1
               t = 1
               For j = i + 1 To qu
                    If _Trim$(soma1(i)) = _Trim$(soma1(j)) And _Trim$(soma1(i)) <> "" Then
                         t = t + 1
                         soma1(j) = ""
                    End If
               Next
               seq(i) = t
               If soma1(i) <> "" Then
                    a = a + 1
                    Color 30
                    Locate a, 3
                    Print "Dez = ";
                    Color 10
                    Locate a, 8
                    Print " "; soma1(i);
                    Color 30
                    Locate a, 12
                    Print "="; seq(i)
               End If
          Next
          '---------------------------------------------------------------------
          a = 12
          For i = 1 To te '- 1
               t = 1
               For j = i + 1 To te
                    If _Trim$(soma2(i)) = _Trim$(soma2(j)) And _Trim$(soma2(i)) <> "" Then
                         t = t + 1
                         soma2(j) = ""
                    End If
               Next
               seq(i) = t
               If soma2(i) <> "" Then
                    a = a + 1
                    Color 30
                    Locate a, 23
                    Print "Dez = ";
                    Color 12
                    Locate a, 28
                    Print " "; soma2(i);
                    Color 30
                    Locate a, 32
                    Print "="; seq(i)
               End If
          Next
          '-----------------------------------------------------------------------

     Else
          Beep
     End If
     Color 13: Locate 44, 58: Print "Pressione [ESC] para sair..."
     x$ = ""
     Scrn$ = InKey$
Loop Until Scrn$ = Chr$(27)

Play "o3l32ceff+g"
Play "mfo4l64ceg>c"
Cls

OE20 = _LoadFont("century.ttf", 82)
_Font OE20
Color 11 ' &H200000FF
Locate 4, 125: Print " QBasic 64 "
Locate 5, 125: Print " -------------- "
_Delay 2
System

'-------------------------------------------------------------------------------------
Function ExtendedInput$ ' Mr. McNeill's extended entrance
     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.
                                   CP = CP + Len(_Clipboard$)
                              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 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 in$
     ExtendedInput$ = in$
     If A Then _AutoDisplay
End Function


