Author Topic: help my  (Read 41423 times)

0 Members and 1 Guest are viewing this topic.

Offline Kiara87

  • Forum Regular
  • Posts: 164
    • View Profile
Re: help my
« Reply #90 on: July 13, 2020, 07:15:21 pm »
@Kiara87

Can you count and list the words in this sentence?

Can you write code to count and list the words in any given sentence?

Can you count the words in reply #85 above? Hope you don't get an overflow error ;-))

Can you count the QB64 CODE words in reply #84?

  [ You are not allowed to view this attachment ]  

Hmm... looks like we will have to do something about punctuation ;-))
says the length of the file as in the image?
@Kiara87
GOTO  e GOSUB sono due bacchette magiche che l'apprendista stregone programmatore deve temere e ammirare. Sono potenti ma senza limiti quindi se non sai quello che stai facendo fai di certo un gran pasticcio, come topolino nell'apprendista stregone https://www.youtube.com/watch?v=U546yRNeNh4

giusto per esercizio e per comprensione  tu poi considerare GOSUB  un GOTO semplificato perchè con RETURN ti permette di ritornare indietro all'istruzione del salto senza usare una ulteriore etichetta
Code: QB64: [Select]
  1. GOTO There
  2. Here:
  3. PRINT "Hi Guys"
  4.  
  5. There:
  6. PRINT "I'm QB64 coder "
  7. GOTO Here
  8.  

is the same that
Code: QB64: [Select]
  1. GOSUB There
  2. PRINT "Hi Guys"
  3.  
  4. There:
  5. PRINT "I'm QB64 coder "
  6.  

ma tu puoi costruire i loop WHILE..WEND, DO WHILE..LOOP, DO UNTIL..LOOP; DO..LOOP UNTIL, DO..LOOP WHILE con i rispettivi EXIT WHILE o EXIT DO usando il GOTO e le etichette, lo stesso per FOR NEXT...
prova come esercizio a creare questi loop con GOTO e li comprenderai meglio.

@bplus
PRINT LEN(88)
:-)
@TempodiBasic  si ho visto esempio che il gosub da un ritorno dal codice da dove era partito ritorna 1 volta nella sua postazione
sto seguendo i tuoi consigli che credo siano la soluzione per imparare a programmare scrivendo in pseudo codice
anche come spiega @SMcNeill dicendo di prendere il problema e dividerlo scomponendolo in sotto problemi
fino a qui ho percepito come mi avevi consigliato di scrivere in pseudocodice
è dividendo in sotto problemi risolvendoli uno ad uno
ma il problema poi sta come converto i problemi al  codice?
come cerco tutte le istruzioni su wiki oppure sul help dvo sempre sapere come cercare quelle istruzioni che servono per convertire il pseudo codice in codice QB64
se avessi solo un'ora per salvare il mondo, passerei 55 minuti per definire bene il problema e 5 a trovare la soluzione

Offline Kiara87

  • Forum Regular
  • Posts: 164
    • View Profile
Re: help my
« Reply #91 on: July 13, 2020, 07:33:40 pm »
thanks to you, you are cunning
by dividing the problem into small problems
and step by step explanation though 'I have to say it with programming code I have to understand how to convert my explanations step by step into programming language
as you did in the example of the peanut sandwich it is easy but the most difficult part is to look for the programming language commands as you said I have to look for the ingredients for the recipe
where do i find them?
on wiki or help
how should i search?
@Kiara87

Can you count and list the words in this sentence?

Can you write code to count and list the words in any given sentence?

Can you count the words in reply #85 above? Hope you don't get an overflow error ;-))

Can you count the QB64 CODE words in reply #84?

  [ You are not allowed to view this attachment ]  

Hmm... looks like we will have to do something about punctuation ;-))



If it helps, Kiara, remember this -- All computer programming breaks down to 3 steps:

1) Step by step commands
2) Decision making
3) Repetition

Take any problem facing you, and you can break its solution down to those 3 steps (including life problems).  Let's say I tell you, "Make me a peanut butter sandwich."   How do you accomplish that task?

Get up.
Go in kitchen.
Get a knife.
Get bread.
Get peanut butter.
Open bread, remove a slice.
Put knife in peanut butter.
Remove knife from peanut butter.
Wipe knife on bread.
Put down knife.
Remove slice of bread from pack.
Place bread on bread.

And there's the biggest problem programmers usually face -- we think "fix a sandwich", and we do it.  The computer has to have that instruction broken down step-by-step, to accomplish the same task...  It's not the complexity of the problem that confound us; it's the simplicity of the computer.

Even with the above set of instructions, it's probably not enough for your pet robot to make that sandwich.  "Get up" implies it was down somewhere.  "Go in kitchen" is vague.  From Where?  How many steps?  How many turns around corners, or up and down steps?  Whose kitchen?

The trick is to break your problem down into smaller stages, and then see if there's a set of computer commands to fulfill those needs.  If not, break those needs down smaller, until there are.

For example let's say I tell you to, "Print the contents of a file for me."

Breaking that order down to its components, we have to:

Choose a file.
Open that file.
Load the contents of that file in memory.
Print that file.
Repeat the last two steps until the whole file is printed.
Close the file.

Now, we have a basic step-by-step road map of how our program will look.

INPUT "Give me the name of the file you want to print ", filename$
OPEN filename$ FOR INPUT AS #1
DO
    LINE INPUT #1, text$
    PRINT text$
LOOP UNTIL EOF(1)
CLOSE #1


Take your complex problem and break it down to its step-by-step components.  If you can do that, you can write your own computer programs.

@bplus  I tried to copy the sentences from the site and save the sentences in txt

I read the file with this
Code: QB64: [Select]
  1. OPEN "leggi.txt" FOR INPUT AS #1
  2. INPUT #1, a$
  3.  

gives me length 86
I had attached image in the previous answer
but I was unable to put the sentences inside
se avessi solo un'ora per salvare il mondo, passerei 55 minuti per definire bene il problema e 5 a trovare la soluzione

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: help my
« Reply #92 on: July 13, 2020, 09:46:14 pm »
Quote
@bplus  I tried to copy the sentences from the site and save the sentences in txt

I read the file with this
Code: QB64: [Select]
OPEN "leggi.txt" FOR INPUT AS #1
INPUT #1, a$
PRINT LEN(a$)
CLOSE
 

gives me length 86
I had attached image in the previous answer
but I was unable to put the sentences inside

OK that is only the length of the first line from the file.


To count words in a sentence (forget about files for moment) you will need these tools:
MID$(aString$, aStartPlace, aLength)
LEN(aString$)

He$ = MID$("Hello World", 1, 2)  ' He$ = "He"
Wor$ = MID$("Hello World", 7, 3) ' Wor$ = "Wor"
d$ = MID$("Hello World", 11, 1)  ' d$ = "d"
PRINT He$+ " " + Wor$ + d$ '  >>>> "He Word"

Code: QB64: [Select]
  1. S$ = "Can you count and list the words in this sentence?"
  2. FOR i = 1 TO LEN(S$)
  3.     letter$ = MID$(S$, i, 1)
  4.     IF letter$ = " " THEN 'the last word$ just ended
  5.         PRINT build$ ' lets show it
  6.         count = count + 1 'let's count it
  7.         build$ = "" 'reset build$ to nothing to build$ another word
  8.     ELSE
  9.         'continue building the word
  10.         build$ = build$ + letter$
  11.     END IF
  12.  
  13. 'now if there is anything left in build$, it is our last word!
  14. IF LEN(build$) THEN
  15.     PRINT build$ ' lets show it
  16.     count = count + 1 'let's count it
  17. PRINT "We had"; count; "words in our sentence."
  18.  

Now you can count and report the number of words in the first line in the file. :)

« Last Edit: July 13, 2020, 09:52:45 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: help my
« Reply #93 on: July 14, 2020, 12:22:10 pm »
About file access when OPEN a file FOR INPUT:

You have 2 ways to read in data from the file: INPUT #fileNum  or LINE INPUT #fileNum

Use INPUT #fileNum when you have a bunch of items on a line separated by commas or you know for sure there are no commas in data lines (like the Lotto Data), INPUT #fileNum won't read past a comma!

If it is likely you have commas or could have commas in a fileLine$ AND you want to read in whole line from the file then use LINE INPUT #fileNum

So here is the template or pattern of code to use when you OPEN a file FOR INPUT as #fileNum
AND want to read in whole lines that might have commas in them:
Code: QB64: [Select]
  1. fileName$ = "My File.txt" '                 the (pathed) file name of the file you want to open
  2. fileNum = FREEFILE '                        FREEFILE gets the next file # ready to use
  3. IF _FILEEXISTS(fileName$) THEN '            to avoid errors check and see if the file actually exists
  4.     OPEN fileName$ FOR INPUT AS #fileNum '  OPEN file for Sequential access = read line by line start to "end of file" = EOF.
  5.     WHILE EOF(1) = 0 '                      While starts a loop of reading in lines until EOF is reached
  6.         LINE INPUT #1, fileLine$ '          reads whole line (with commas) into variable fileLine$
  7.  
  8.         'process fileLine$
  9.  
  10.     WEND '                                  WEND closes a WHILE Loop Structure
  11.     CLOSE #fileNum '                        close file, we are done with it
  12.     PRINT "Sorry, could not find your file: "; fileName$
  13.  
  14.  

EOF(fileNum) is a flag that is 0 = False until the last line has been read, it is then set to TRUE = NOT False usually -1
« Last Edit: July 14, 2020, 12:28:02 pm by bplus »

Offline Kiara87

  • Forum Regular
  • Posts: 164
    • View Profile
Re: help my
« Reply #94 on: July 14, 2020, 07:56:49 pm »
@bplus thanks bplus everything is useful to learn
I am trying to finish my lotto program
I have to try to figure out how to put the draw date again

in both draws which are now two
it is also how to change the values in the second extraction on the right
in the sense if in the left draw there is a distance 30 in the other draw must mark the numbers to play
Code: QB64: [Select]
  1. ' Programma lotto di kiara87
  2. ' il programma legge i dati (numeri estratti da un file.dat)
  3. ' e permette di vedere  le estrazioni a video
  4. ' i numeri con distanza 30 sono evidenziati con colore rosso
  5. ' questi numeri vengono memorizzati e stampati
  6.  
  7. ' Nota 1: sono d'accordo con Bplus e' molto piu'
  8. ' rapido lavorare con dati in RAM che con dati su Disco HDD/SSD/USB/CD/DVD
  9.  
  10. ' valori COSTANTI  generali Vero e Falso
  11. CONST True = -1, False = NOT True
  12. ' le 11 ruote del lotto
  13. CONST Bari = 1, Cagliari = 2, Firenze = 3, Genova = 4, Milano = 5
  14. CONST Napoli = 6, Palermo = 7, Roma = 8, Torino = 9, Venezia = 10, Nazionale = 11
  15. CONST Cifra = 2 ' ogni numero estratto e' una cifra di due caratteri (01-90)
  16.  
  17. DIM a AS STRING ' una stringa per leggere i dati dal file
  18.  
  19. ' salta al sottoprogramma LeggiFile delimitato
  20. ' dalla Label LeggiFIle e dal RETURN
  21. GOSUB LeggiFile
  22.  
  23. ' verifica che tutto il file sia letto
  24. 'FOR b = 1 TO LEN(a) - 116 STEP 116
  25. '    PRINT MID$(a, b, 116)
  26. '    '    PRINT INSTR(b, a, CHR$(13))
  27. '    _DELAY .1
  28. 'NEXT b
  29.  
  30.  
  31.  
  32. ' il ciclo DO...LOOP UNTIL condizione e' un modo piu' moderno
  33. ' rispetto a Etichetta: .... IF condizione GOTO Etichetta
  34. b = 1
  35. f = 1
  36. z$ = " "
  37. OPEN "distanza30.dat" FOR APPEND AS #2
  38.     IF z$ <> "" THEN
  39.         CLS ' questo risolve un glitch di output sullo schermo
  40.         ' in alternativa alla riga sopra CLS nel sottoblocco
  41.         ' MostraEstratti va stampata la stringa estratto e
  42.         ' non il suo valore corrispondente ottenuto con VAL
  43.         GOSUB MostraRuote ' scrive il nome delle ruote del lotto
  44.         GOSUB MostraEstratti
  45.     END IF
  46.     ' prende l'input dell'utente
  47.     z$ = UCASE$(INKEY$) ' Z$ mantiene il maiuscolo di Inkey$
  48.     IF z$ = CHR$(0) + CHR$(72) AND b < (LEN(a) - 116) THEN b = b + 116
  49.     IF z$ = CHR$(0) + CHR$(80) AND b > 116 THEN b = b - 116
  50.     IF z$ = "+" AND f < (LEN(a) - 116) THEN f = f + 116
  51.     IF z$ = "-" AND f > 116 THEN f = f - 116
  52.  
  53. LOOP UNTIL z$ = "Q"
  54.  
  55. END ' indica la fine logica del programma
  56.  
  57.  
  58. '-----------------------AREA sottoprogrammi /SUBroutines
  59.  
  60. ' questa etichetta /label indica il punto di inizio
  61. ' del sottoprogramma (SUBroutine) LeggiFile scritto con vecchio stile GOSUB
  62. ' che usa una etichetta/label e un RETURN per riprendere da dove si era interotto
  63. ' nota1: un metodo ancora piu' antico e' il salto con GOTO
  64. '        che richiede una seconda etichetta per ritornare nel MAIN o programma principale
  65. ' nota2: un metodo migliore e' SUB nomeroutine....END SUB
  66. '        perche' permette la localizzazione delle variabili
  67. LeggiFile:
  68. 'se non trova lotto.dat segnala l'errore a video e termina il programma
  69. IF NOT _FILEEXISTS("lotto.dat") THEN PRINT "File non trovato": END
  70. '<--------------------
  71. ' questo metodo e' piu' lento
  72. ' apre il file lotto.dat per leggere in maniera sequenziale i dati
  73. 'OPEN "lotto.dat" FOR INPUT AS #1
  74. 'LINE INPUT #1, a  ' riempe la variabile a con una riga intera di valori
  75. '<--------------------
  76.  
  77. ' apre lotto.dat per leggerlo in maniera binaria
  78. OPEN "lotto.dat" FOR BINARY AS #1
  79. a = SPACE$(LOF(1)) ' riempe la variabile a di spazi fino alla grandezza in byte del file aperto
  80. GET #1, , a ' legge con una unica operazione il file e lo pone nella variabiel a
  81. CLOSE #1 ' chiude il file appena letto
  82. ' indica il termine della SUBroutine LeggiFile
  83. ' e RITORNA alla riga di codice successiva al salto GOSUB
  84.  
  85. 'seconda SUBroutine /sottoprogramma
  86. MostraRuote:
  87. LOCATE 1, 1
  88. PRINT "BARI"
  89. LOCATE 3, 1
  90. PRINT "CAGLIARI"
  91. LOCATE 5, 1
  92. PRINT "FIRENZE"
  93. LOCATE 7, 1
  94. PRINT "GENOVA"
  95. LOCATE 9, 1
  96. PRINT "MILANO"
  97. LOCATE 11, 1
  98. PRINT "NAPOLI"
  99. LOCATE 13, 1
  100. PRINT "PALERMO"
  101. LOCATE 15, 1
  102. PRINT "ROMA"
  103. LOCATE 17, 1
  104. PRINT "TORINO"
  105. LOCATE 19, 1
  106. PRINT "VENEZIA"
  107. LOCATE 21, 1
  108. PRINT "NAZIONALE"
  109. LOCATE 1, 50
  110. PRINT "BARI"
  111. LOCATE 3, 50
  112. PRINT "CAGLIARI"
  113. LOCATE 5, 50
  114. PRINT "FIRENZE"
  115. LOCATE 7, 50
  116. PRINT "GENOVA"
  117. LOCATE 9, 50
  118. PRINT "MILANO"
  119. LOCATE 11, 50
  120. PRINT "NAPOLI"
  121. LOCATE 13, 50
  122. PRINT "PALERMO"
  123. LOCATE 15, 50
  124. PRINT "ROMA"
  125. LOCATE 17, 50
  126. PRINT "TORINO"
  127. LOCATE 19, 50
  128. PRINT "VENEZIA"
  129. LOCATE 21, 50
  130. PRINT "NAZIONALE"
  131.  
  132. '------------------------------------
  133. LOCATE 23, 60
  134. PRINT "+ avanti  - indietro"
  135. LOCATE 23, 1
  136. PRINT "su e' giu'"
  137.  
  138. ' indica il termine della SUBroutine MostraRuote
  139. ' e RITORNA alla riga di codice successiva al salto GOSUB
  140.  
  141. 'terzo sottoprogramma o SUBroutine
  142. MostraEstratti:
  143.  
  144. ' le prime 4 cifre sembrano essere in numero della estrazione
  145. LOCATE 1, 32
  146. PRINT "estraz.num "; MID$(a, b, 4)
  147. PRINT #2, "estraz.num "; MID$(a, b, 4)
  148. y = 11 ' prima posizione per il carattere da stampare
  149. FOR x = 1 TO 5 STEP 1 ' questo ciclo   FOR e' di 5 perche' ogni ruota ha 5 estrazioni
  150.     A1 = "" ' resetto a1 per il prossimo giro
  151.     FOR V = Bari TO Nazionale ' per tutte le ruote
  152.         COLOR 15, 0
  153.         'posiziona il cursore
  154.         LOCATE (V * 2) - 1, y
  155.         ' scrive il numero estratto
  156.         PRINT VAL(MID$(a, (V - 1) * 10 + 5 + ((x - 1) * 2) + (b - 1), Cifra)); "";
  157.         A1 = A1 + (MID$(a, (V - 1) * 10 + 5 + ((x - 1) * 2) + (b - 1), Cifra))
  158.     NEXT V
  159.     GOSUB Mostra30
  160.     y = POS(0)
  161. ' indica il termine della SUBroutine MostraEstratti
  162. ' e RITORNA alla riga di codice successiva al salto GOSUB
  163. LOCATE 23, 32
  164. PRINT "estraz.num "; MID$(a, f, 4)
  165. PRINT #2, "estraz.num "; MID$(a, f, 4)
  166.  
  167. y = 58 ' prima posizione per il carattere da stampare
  168. FOR x = 1 TO 5 STEP 1 ' questo ciclo   FOR e' di 5 perche' ogni ruota ha 5 estrazioni
  169.     A1 = "" ' resetto a1 per il prossimo giro
  170.     FOR V = Bari TO Nazionale ' per tutte le ruote
  171.         COLOR 15, 0
  172.         'posiziona il cursore
  173.         LOCATE (V * 2) - 1, y
  174.         ' scrive il numero estratto
  175.         PRINT VAL(MID$(a, (V - 1) * 10 + 5 + ((x - 1) * 2) + (f - 1), Cifra)); "";
  176.         A1 = A1 + (MID$(a, (V - 1) * 10 + 5 + ((x - 1) * 2) + (f - 1), Cifra))
  177.     NEXT V
  178.     GOSUB MostraCondizione
  179.     y = POS(0)
  180. ' indica il termine della SUBroutine MostraEstratti
  181. ' e RITORNA alla riga di codice successiva al salto GOSUB
  182.  
  183.  
  184.  
  185.  
  186. Mostra30:
  187. FOR v1 = Bari TO Venezia ' per tutte le ruote
  188.     FOR v2 = v1 + 1 TO Nazionale
  189.         IF ABS(VAL(MID$(a, (v1 - 1) * 10 + 5 + ((x - 1) * 2) + (b - 1), Cifra)) - VAL(MID$(a, (v2 - 1) * 10 + 5 + ((x - 1) * 2) + (b - 1), Cifra))) = 30 THEN
  190.             COLOR 10, 0
  191.             'posiziona                                                                      il cursore
  192.             LOCATE (v1 * 2) - 1, y
  193.             ' scrive il numero estratto
  194.             PRINT VAL(MID$(a, (v1 - 1) * 10 + 5 + ((x - 1) * 2) + (b - 1), Cifra)); "";
  195.             PRINT #2, (MID$(a, (v1 - 1) * 10 + 5 + ((x - 1) * 2) + (b - 1), Cifra))
  196.             'posiziona                                                                      il cursore
  197.             LOCATE (v2 * 2) - 1, y
  198.             ' scrive il numero estratto
  199.             PRINT VAL(MID$(a, (v2 - 1) * 10 + 5 + ((x - 1) * 2) + (b - 1), Cifra)); "";
  200.             PRINT #2, MID$(a, (v2 - 1) * 10 + 5 + ((x - 1) * 2) + (b - 1), Cifra)
  201.         END IF
  202.     NEXT v2
  203. NEXT v1
  204. COLOR 15, 0
  205. ' indica il termine della SUBroutine MostraEstratti
  206. ' e RITORNA alla riga di codice successiva al salto GOSUB
  207.  
  208. MostraCondizione:
  209. FOR v3 = Bari TO Venezia ' per tutte le ruote
  210.     FOR v4 = v3 + 1 TO Nazionale
  211.         IF ABS(VAL(MID$(a, (v3 - 1) * 10 + 5 + ((x - 1) * 2) + (f - 1), Cifra)) - VAL(MID$(a, (v4 - 1) * 10 + 5 + ((x - 1) * 2) + (f - 1), Cifra))) = 30 THEN
  212.             COLOR 4, 0
  213.             'posiziona                                                                      il cursore
  214.             LOCATE (v3 * 2) - 1, y
  215.             ' scrive il numero estratto
  216.             PRINT VAL(MID$(a, (v3 - 1) * 10 + 5 + ((x - 1) * 2) + (f - 1), Cifra)); "";
  217.             PRINT #2, (MID$(a, (v3 - 1) * 10 + 5 + ((x - 1) * 2) + (f - 1), Cifra))
  218.             'posiziona                                                                      il cursore
  219.             LOCATE (v4 * 2) - 1, y
  220.             ' scrive il numero estratto
  221.             PRINT VAL(MID$(a, (v4 - 1) * 10 + 5 + ((x - 1) * 2) + (f - 1), Cifra)); "";
  222.             PRINT #2, MID$(a, (v4 - 1) * 10 + 5 + ((x - 1) * 2) + (f - 1), Cifra)
  223.         END IF
  224.     NEXT v4
  225. NEXT v3
  226. COLOR 15, 0
  227. ' indica il termine della SUBroutine MostraEstratti
  228. ' e RITORNA alla riga di codice successiva al salto GOSUB
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  

un po difficile da spiegare in inglese
magari @TempodiBasic  puo' capire spiegandolo in italiano hihi

I don't know if I write a mess with this translator and maybe you don't really understand what I mean

However, I must say that I am learning a lot from you
even with the sample program you did for me

and also your advice
I thank all of you who are very good

anche @TempodiBasic  con i suoi commenti e' il suo codice sorgente con tanto di commenti in italiano mi ha fatto capire i comandi
alcuni ancora devo capire abs come funziona facendo le operazioni oppure bisogna conoscere tanta matematica per usarla
@bplus you have been very helpful in creating the program for me and always posting examples
also being very good at programming you are very kind to always help others trying to learn from other people
maybe this is the reason that made you improve so much in programming
he made you grow to learn others and in the meantime you also learned

thank you all



se avessi solo un'ora per salvare il mondo, passerei 55 minuti per definire bene il problema e 5 a trovare la soluzione

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: help my
« Reply #95 on: July 15, 2020, 11:16:19 am »
Quote
I have to try to figure out how to put the draw date again

in both draws which are now two
it is also how to change the values in the second extraction on the right
in the sense if in the left draw there is a distance 30 in the other draw must mark the numbers to play

RE Draw date: Is the draw date the first 4 digits of each row in the data file?

RE dist30 between values: you removed the separate function and embedded it into the display code. In my opinion it was better to have that function isolated, perhaps you are afraid of FUNCTIONs ?

But you use FUNCTIONs all the time LEN(aString$) is a FUNCTION, so is VAL(), and MID$(), EOF(), LOF() these are functions you already use. A FUNCTION is just one you make for yourself and is just as easy to use once it's made.
Oh well you are new and newbies want to avoid Arrays, Subs and Functions...

It looks now that you've made the file data one very long string and use code to chop it down to blocks then rows and columns of data, use that same technique to locate the two numbers in question to test their distance.

I am not certain which 2 numbers you want the 30's difference to be calculated, I would guess in the corresponding row, col of the left side that is on the right side so every time you arrow or +/- you have to recalculate the display.

If so, use the same calculation you use to display a number in a page (right side or left), block (labels), row and column to compare the numbers between left side and the right.

In my opinion it was easier to understand taking data a row at a time and keeping the 30 distance function separate. Maybe this is from TempodiBasic influence? It is clever to swallow the whole file in one gulp but you still have to deal with CR+LF and then deal with a 3rd DIM to the data the dates is it? What are those first 4 digits in each line?

Are you here to gain some superstitious edge on lotto's or to learn coding?

I know, BOTH! ;-))

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: help my
« Reply #96 on: July 15, 2020, 11:34:50 am »
Assuming date is first 4 digits of each line in data file:

OK so the length of each line of data is 116 counting the CR+LF that would be still embedded in the whole file string so each date would start at 1 + 0 * 116, 1 + 1 * 116, 1 + 2 * 116...

FUNCTION date$(lineNum)
    date$ = MID$(a, 1 + (lineNum - 1) * 116, 4)  ' a = the SHARED data file string
END FUNCTION


lineNum is same as row number in the data file.

Name Conflict with DATE$ sorry forgot:
Code: QB64: [Select]
  1. FUNCTION LottoDate$ (lineNum)
  2.     Lottodate$ = MID$(a, 1 + (lineNum - 1) * 116, 4)  ' a = the SHARED data file string
  3.  
  4.  
  5.  
« Last Edit: July 15, 2020, 05:51:40 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: help my
« Reply #97 on: July 15, 2020, 05:58:55 pm »
Test function, load it at bottom of code and top section of code looks like this:

Code: QB64: [Select]
  1. CONST True = -1, False = NOT True
  2. ' le 11 ruote del lotto
  3. CONST Bari = 1, Cagliari = 2, Firenze = 3, Genova = 4, Milano = 5
  4. CONST Napoli = 6, Palermo = 7, Roma = 8, Torino = 9, Venezia = 10, Nazionale = 11
  5. CONST Cifra = 2 ' ogni numero estratto e' una cifra di due caratteri (01-90)
  6.  
  7. DIM SHARED a AS STRING ' una stringa per leggere i dati dal file  <<<<<<<<<<<<<<<<< SHARED
  8.  
  9. ' salta al sottoprogramma LeggiFile delimitato
  10. ' dalla Label LeggiFIle e dal RETURN
  11. GOSUB LeggiFile
  12.  
  13. 'test fuction after load file into a string
  14. PRINT LottoDate$(1)
  15. PRINT LottoDate$(2)
  16. PRINT LottoDate$(3)
  17.  
  18.  

« Last Edit: July 15, 2020, 06:00:46 pm by bplus »

Offline Kiara87

  • Forum Regular
  • Posts: 164
    • View Profile
Re: help my
« Reply #98 on: July 15, 2020, 06:12:07 pm »
Assuming date is first 4 digits of each line in data file:

OK so the length of each line of data is 116 counting the CR+LF that would be still embedded in the whole file string so each date would start at 1 + 0 * 116, 1 + 1 * 116, 1 + 2 * 116...

FUNCTION date$(lineNum)
    date$ = MID$(a, 1 + (lineNum - 1) * 116, 4)  ' a = the SHARED data file string
END FUNCTION


lineNum is same as row number in the data file.

Name Conflict with DATE$ sorry forgot:
Code: QB64: [Select]
  1. FUNCTION LottoDate$ (lineNum)
  2.     Lottodate$ = MID$(a, 1 + (lineNum - 1) * 116, 4)  ' a = the SHARED data file string
  3.  
  4.  
  5.  

the problem is that I still don't know the commands well and how to program them
because I was initially editing your code
but not being able to understand where I got my hands maybe because I didn't understand how the functions work the arrays in your code look for many variables and I didn't know what to change because every single variable makes its path and I didn't know what one of those variables does
after I got the code @TempodiBasic 
there I understood something because he in the written comments how they work is in his code he didn't use many variables but few variables
in its code there is no functions

so I found it easier to edit its code

put an example of what I walked between the two codes
source code @TempodiBasic mod kiara
Code: QB64: [Select]
  1. ' Programma lotto di kiara87
  2. ' il programma legge i dati (numeri estratti da un file.dat)
  3. ' e permette di vedere  le estrazioni a video
  4. ' i numeri con distanza 30 sono evidenziati con colore rosso
  5. ' questi numeri vengono memorizzati e stampati
  6.  
  7. ' Nota 1: sono d'accordo con Bplus e' molto piu'
  8. ' rapido lavorare con dati in RAM che con dati su Disco HDD/SSD/USB/CD/DVD
  9.  
  10. ' valori COSTANTI  generali Vero e Falso
  11. CONST True = -1, False = NOT True
  12. ' le 11 ruote del lotto
  13. CONST Bari = 1, Cagliari = 2, Firenze = 3, Genova = 4, Milano = 5
  14. CONST Napoli = 6, Palermo = 7, Roma = 8, Torino = 9, Venezia = 10, Nazionale = 11
  15. CONST Cifra = 2 ' ogni numero estratto e' una cifra di due caratteri (01-90)
  16.  
  17. DIM a AS STRING ' una stringa per leggere i dati dal file
  18.  
  19. ' salta al sottoprogramma LeggiFile delimitato
  20. ' dalla Label LeggiFIle e dal RETURN
  21. GOSUB LeggiFile
  22.  
  23. ' verifica che tutto il file sia letto
  24. 'FOR b = 1 TO LEN(a) - 116 STEP 116
  25. '    PRINT MID$(a, b, 116)
  26. '    '    PRINT INSTR(b, a, CHR$(13))
  27. '    _DELAY .1
  28. 'NEXT b
  29.  
  30.  
  31.  
  32. ' il ciclo DO...LOOP UNTIL condizione e' un modo piu' moderno
  33. ' rispetto a Etichetta: .... IF condizione GOTO Etichetta
  34. b = 1
  35. f = 1
  36. z$ = " "
  37. OPEN "distanza30.dat" FOR APPEND AS #2
  38.     IF z$ <> "" THEN
  39.         CLS ' questo risolve un glitch di output sullo schermo
  40.         ' in alternativa alla riga sopra CLS nel sottoblocco
  41.         ' MostraEstratti va stampata la stringa estratto e
  42.         ' non il suo valore corrispondente ottenuto con VAL
  43.         GOSUB MostraRuote ' scrive il nome delle ruote del lotto
  44.         GOSUB MostraEstratti
  45.     END IF
  46.     ' prende l'input dell'utente
  47.     z$ = UCASE$(INKEY$) ' Z$ mantiene il maiuscolo di Inkey$
  48.     IF z$ = CHR$(0) + CHR$(72) AND b < (LEN(a) - 116) THEN b = b + 116
  49.     IF z$ = CHR$(0) + CHR$(80) AND b > 116 THEN b = b - 116
  50.     IF z$ = "+" AND f < (LEN(a) - 116) THEN f = f + 116
  51.     IF z$ = "-" AND f > 116 THEN f = f - 116
  52.  
  53. LOOP UNTIL z$ = "Q"
  54.  
  55. END ' indica la fine logica del programma
  56.  
  57.  
  58. '-----------------------AREA sottoprogrammi /SUBroutines
  59.  
  60. ' questa etichetta /label indica il punto di inizio
  61. ' del sottoprogramma (SUBroutine) LeggiFile scritto con vecchio stile GOSUB
  62. ' che usa una etichetta/label e un RETURN per riprendere da dove si era interotto
  63. ' nota1: un metodo ancora piu' antico e' il salto con GOTO
  64. '        che richiede una seconda etichetta per ritornare nel MAIN o programma principale
  65. ' nota2: un metodo migliore e' SUB nomeroutine....END SUB
  66. '        perche' permette la localizzazione delle variabili
  67. LeggiFile:
  68. 'se non trova lotto.dat segnala l'errore a video e termina il programma
  69. IF NOT _FILEEXISTS("lotto.dat") THEN PRINT "File non trovato": END
  70. '<--------------------
  71. ' questo metodo e' piu' lento
  72. ' apre il file lotto.dat per leggere in maniera sequenziale i dati
  73. 'OPEN "lotto.dat" FOR INPUT AS #1
  74. 'LINE INPUT #1, a  ' riempe la variabile a con una riga intera di valori
  75. '<--------------------
  76.  
  77. ' apre lotto.dat per leggerlo in maniera binaria
  78. OPEN "lotto.dat" FOR BINARY AS #1
  79. a = SPACE$(LOF(1)) ' riempe la variabile a di spazi fino alla grandezza in byte del file aperto
  80. GET #1, , a ' legge con una unica operazione il file e lo pone nella variabiel a
  81. CLOSE #1 ' chiude il file appena letto
  82. ' indica il termine della SUBroutine LeggiFile
  83. ' e RITORNA alla riga di codice successiva al salto GOSUB
  84.  
  85. 'seconda SUBroutine /sottoprogramma
  86. MostraRuote:
  87. LOCATE 1, 1
  88. PRINT "BARI"
  89. LOCATE 3, 1
  90. PRINT "CAGLIARI"
  91. LOCATE 5, 1
  92. PRINT "FIRENZE"
  93. LOCATE 7, 1
  94. PRINT "GENOVA"
  95. LOCATE 9, 1
  96. PRINT "MILANO"
  97. LOCATE 11, 1
  98. PRINT "NAPOLI"
  99. LOCATE 13, 1
  100. PRINT "PALERMO"
  101. LOCATE 15, 1
  102. PRINT "ROMA"
  103. LOCATE 17, 1
  104. PRINT "TORINO"
  105. LOCATE 19, 1
  106. PRINT "VENEZIA"
  107. LOCATE 21, 1
  108. PRINT "NAZIONALE"
  109. LOCATE 1, 50
  110. PRINT "BARI"
  111. LOCATE 3, 50
  112. PRINT "CAGLIARI"
  113. LOCATE 5, 50
  114. PRINT "FIRENZE"
  115. LOCATE 7, 50
  116. PRINT "GENOVA"
  117. LOCATE 9, 50
  118. PRINT "MILANO"
  119. LOCATE 11, 50
  120. PRINT "NAPOLI"
  121. LOCATE 13, 50
  122. PRINT "PALERMO"
  123. LOCATE 15, 50
  124. PRINT "ROMA"
  125. LOCATE 17, 50
  126. PRINT "TORINO"
  127. LOCATE 19, 50
  128. PRINT "VENEZIA"
  129. LOCATE 21, 50
  130. PRINT "NAZIONALE"
  131.  
  132. '------------------------------------
  133. LOCATE 23, 60
  134. PRINT "+ avanti  - indietro"
  135. LOCATE 23, 1
  136. PRINT CHR$(24); " avanti   "; CHR$(25); " indietro"
  137.  
  138. ' indica il termine della SUBroutine MostraRuote
  139. ' e RITORNA alla riga di codice successiva al salto GOSUB
  140.  
  141. 'terzo sottoprogramma o SUBroutine
  142. MostraEstratti:
  143.  
  144. ' le prime 4 cifre sembrano essere in numero della estrazione
  145. LOCATE 1, 32
  146. PRINT "estraz.num "; MID$(a, b, 4)
  147. PRINT #2, "estraz.num "; MID$(a, b, 4)
  148. y = 11 ' prima posizione per il carattere da stampare
  149. FOR x = 1 TO 5 STEP 1 ' questo ciclo   FOR e' di 5 perche' ogni ruota ha 5 estrazioni
  150.     A1 = "" ' resetto a1 per il prossimo giro
  151.     FOR V = Bari TO Nazionale ' per tutte le ruote
  152.         COLOR 15, 0
  153.         'posiziona il cursore
  154.         LOCATE (V * 2) - 1, y
  155.         ' scrive il numero estratto
  156.         PRINT VAL(MID$(a, (V - 1) * 10 + 5 + ((x - 1) * 2) + (b - 1), Cifra)); "";
  157.         A1 = A1 + (MID$(a, (V - 1) * 10 + 5 + ((x - 1) * 2) + (b - 1), Cifra))
  158.     NEXT V
  159.     GOSUB Mostra30
  160.     y = POS(0)
  161. ' indica il termine della SUBroutine MostraEstratti
  162. ' e RITORNA alla riga di codice successiva al salto GOSUB
  163. LOCATE 23, 32
  164. PRINT "estraz.num "; MID$(a, f, 4)
  165. PRINT #2, "estraz.num "; MID$(a, f, 4)
  166.  
  167. y = 58 ' prima posizione per il carattere da stampare
  168. FOR x = 1 TO 5 STEP 1 ' questo ciclo   FOR e' di 5 perche' ogni ruota ha 5 estrazioni
  169.     A1 = "" ' resetto a1 per il prossimo giro
  170.     FOR V = Bari TO Nazionale ' per tutte le ruote
  171.         COLOR 15, 0
  172.         'posiziona il cursore
  173.         LOCATE (V * 2) - 1, y
  174.         ' scrive il numero estratto
  175.         PRINT VAL(MID$(a, (V - 1) * 10 + 5 + ((x - 1) * 2) + (f - 1), Cifra)); "";
  176.         A1 = A1 + (MID$(a, (V - 1) * 10 + 5 + ((x - 1) * 2) + (f - 1), Cifra))
  177.     NEXT V
  178.     GOSUB MostraCondizione
  179.     y = POS(0)
  180. ' indica il termine della SUBroutine MostraEstratti
  181. ' e RITORNA alla riga di codice successiva al salto GOSUB
  182.  
  183.  
  184.  
  185.  
  186. Mostra30:
  187. FOR v1 = Bari TO Venezia ' per tutte le ruote
  188.     FOR v2 = v1 + 1 TO Nazionale
  189.         IF ABS(VAL(MID$(a, (v1 - 1) * 10 + 5 + ((x - 1) * 2) + (b - 1), Cifra)) - VAL(MID$(a, (v2 - 1) * 10 + 5 + ((x - 1) * 2) + (b - 1), Cifra))) = 30 THEN
  190.             COLOR 10, 0
  191.             'posiziona                                                                      il cursore
  192.             LOCATE (v1 * 2) - 1, y
  193.             ' scrive il numero estratto
  194.             PRINT VAL(MID$(a, (v1 - 1) * 10 + 5 + ((x - 1) * 2) + (b - 1), Cifra)); "";
  195.             PRINT #2, (MID$(a, (v1 - 1) * 10 + 5 + ((x - 1) * 2) + (b - 1), Cifra))
  196.             'posiziona                                                                      il cursore
  197.             LOCATE (v2 * 2) - 1, y
  198.             ' scrive il numero estratto
  199.             PRINT VAL(MID$(a, (v2 - 1) * 10 + 5 + ((x - 1) * 2) + (b - 1), Cifra)); "";
  200.             PRINT #2, MID$(a, (v2 - 1) * 10 + 5 + ((x - 1) * 2) + (b - 1), Cifra)
  201.         END IF
  202.     NEXT v2
  203. NEXT v1
  204. COLOR 15, 0
  205. ' indica il termine della SUBroutine MostraEstratti
  206. ' e RITORNA alla riga di codice successiva al salto GOSUB
  207.  
  208. MostraCondizione:
  209. FOR v3 = Bari TO Venezia ' per tutte le ruote
  210.     FOR v4 = v3 + 1 TO Nazionale
  211.         IF ABS(VAL(MID$(a, (v3 - 1) * 10 + 5 + ((x - 1) * 2) + (f - 1), Cifra)) - VAL(MID$(a, (v4 - 1) * 10 + 5 + ((x - 1) * 2) + (f - 1), Cifra))) = 30 THEN
  212.             COLOR 4, 0
  213.             'posiziona                                                                      il cursore
  214.             LOCATE (v3 * 2) - 1, y
  215.             ' scrive il numero estratto
  216.             PRINT VAL(MID$(a, (v3 - 1) * 10 + 5 + ((x - 1) * 2) + (f - 1), Cifra)); "";
  217.             PRINT #2, (MID$(a, (v3 - 1) * 10 + 5 + ((x - 1) * 2) + (f - 1), Cifra))
  218.             'posiziona                                                                      il cursore
  219.             LOCATE (v4 * 2) - 1, y
  220.             ' scrive il numero estratto
  221.             PRINT VAL(MID$(a, (v4 - 1) * 10 + 5 + ((x - 1) * 2) + (f - 1), Cifra)); "";
  222.             PRINT #2, MID$(a, (v4 - 1) * 10 + 5 + ((x - 1) * 2) + (f - 1), Cifra)
  223.         END IF
  224.     NEXT v4
  225. NEXT v3
  226. COLOR 15, 0
  227. ' indica il termine della SUBroutine MostraEstratti
  228. ' e RITORNA alla riga di codice successiva al salto GOSUB
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  


source code @bplus  mod 2 kiara
Code: QB64: [Select]
  1. OPTION _EXPLICIT 'for typo's   yep lineMun blah!
  2.  
  3. DEFINT A-Z ' everything is integer unless DIM or suffix
  4. CONST nRows = 11 'rows of 5 data points in each line of fileDat
  5. DIM a AS STRING, count, count2, i, lineNum, lineNum2 ' for file and array access
  6. DIM Q$ '                             for INKEY$
  7. DIM row, col, aPlace, aPlace2 '               for screening Data from a string
  8. DIM rowCnt, x, y, d, rowPlus '       for loading lineDAT() from a file string
  9. DIM lineDAT(1 TO 5, 1 TO nRows) AS INTEGER 'an  array to load from each line from DAT
  10. DIM shiftRight
  11. DIM shiftRight2
  12. shiftRight2 = 65
  13. shiftRight = 15
  14.  
  15. 'count lines in file
  16. OPEN "lotto.dat" FOR INPUT AS #1
  17.     INPUT #1, a
  18.     '          debug check inputs from file
  19.     'PRINT a
  20.     'INPUT " OK enter "; w$
  21.     IF LEN(_TRIM$(a)) THEN count = count + 1 'don't want empty lines _TRIM$ removes spaces or other nonsense
  22.  
  23. 'now we now size of file so ready an array to load file Data
  24. DIM fileDAT(1 TO count) AS STRING
  25. OPEN "lotto.dat" FOR INPUT AS #1
  26. FOR i = 1 TO count
  27.     INPUT #1, a
  28.     IF LEN(_TRIM$(a)) THEN fileDAT(i) = a 'don't want empty lines _TRIM$ removes spaces or other nonsense
  29.  
  30. ' NOW all the data if loaded into fileDAT() array, 480 strings of Lottory data
  31.  
  32. GOSUB labelScreen
  33.  
  34. 'set first line and get a data string from the FileDAT array
  35. lineNum = 1
  36. a = fileDAT(lineNum)
  37.  
  38.     Q$ = INKEY$
  39.     IF Q$ = "+" THEN lineNum = lineNum + 1
  40.     IF Q$ = "-" THEN lineNum = lineNum - 1
  41.     IF Q$ = CHR$(0) + CHR$(72) THEN lineNum = lineNum + 1
  42.     IF Q$ = CHR$(0) + CHR$(80) THEN lineNum = lineNum - 1
  43.  
  44.     IF lineNum > count THEN lineNum = 1
  45.     IF lineNum < 1 THEN lineNum = count
  46.  
  47.     'get new data line
  48.     a = fileDAT(lineNum)
  49.  
  50.  
  51.     'print out the data from the new line
  52.     CLS
  53.     GOSUB labelScreen
  54.     GOSUB screenDataLine
  55.     GOSUB loadLineDAT_Mark30s
  56.     _DISPLAY
  57.     _LIMIT 30
  58.  
  59.  
  60. loadLineDAT_Mark30s: 'this  loads the lineDAT array, so we can sweep through the columes and mark 30's
  61. rowCnt = 1: y = 1
  62. FOR i = 5 TO LEN(a) STEP 2 ' is marking off the start of each data 2 digit integer
  63.     lineDAT(rowCnt, y) = VAL(MID$(a, i, 2)) 'convert data item to integer
  64.     rowCnt = rowCnt + 1 ' increase column if at 6 start new row
  65.     IF rowCnt = 6 THEN y = y + 1: rowCnt = 1
  66. COLOR 9 'blue marker  seacrh through columes for  30's
  67. FOR col = 1 TO 5 'for each of the columes of data
  68.     FOR row = 1 TO 10 'for each of the rows of dat
  69.         FOR rowPlus = row + 1 TO 11 'compare the next rows for diff 30 with current col, row
  70.             IF diff30in90(lineDAT(col, row), lineDAT(col, rowPlus)) THEN
  71.                 LOCATE row * 2, col * 3 - 2 + shiftRight: PRINT DD$(lineDAT(col, row));
  72.                 LOCATE rowPlus * 2, col * 3 - 2 + shiftRight: PRINT DD$(lineDAT(col, rowPlus));
  73.                 '--------------------------------------------------------------------------
  74.  
  75.                 LOCATE row * 2, col * 3 - 2 + shiftRight2: PRINT DD$(lineDAT(col, row));
  76.                 LOCATE rowPlus * 2, col * 3 - 2 + shiftRight2: PRINT DD$(lineDAT(col, rowPlus));
  77.  
  78.             END IF
  79.         NEXT
  80.     NEXT
  81.  
  82.  
  83. screenDataLine:
  84. LOCATE 1, 34
  85. PRINT "estraz.num "; LEFT$(a, 4); "   lineNum:"; STR$(lineNum);
  86. aPlace = 5
  87. FOR row = 1 TO 11
  88.     FOR col = 1 TO 5
  89.         LOCATE row * 2, col * 3 - 2 + shiftRight: PRINT MID$(a, aPlace, 2);
  90.         aPlace = aPlace + 2
  91.     NEXT
  92. '------------------------------------------------------------------------
  93. LOCATE 1, 34
  94. PRINT "estraz.num "; LEFT$(a, 4); "   lineNum:"; STR$(lineNum);
  95. aPlace = 5
  96. FOR row = 1 TO 11
  97.     FOR col = 1 TO 5
  98.         LOCATE row * 2, col * 3 - 2 + shiftRight2: PRINT MID$(a, aPlace, 2);
  99.         aPlace = aPlace + 2
  100.     NEXT
  101.  
  102.  
  103.  
  104. labelScreen:
  105. ' setup screen labels for reporting data
  106. LOCATE 2, 1
  107. PRINT "BARI"
  108. LOCATE 4, 1
  109. PRINT "CAGLIARI"
  110. LOCATE 6, 1
  111. PRINT "FIRENZE"
  112. LOCATE 8, 1
  113. PRINT "GENOVA"
  114. LOCATE 10, 1
  115. PRINT "MILANO"
  116. LOCATE 12, 1
  117. PRINT "NAPOLI"
  118. LOCATE 16, 1
  119. PRINT "PALERMO"
  120. LOCATE 18, 1
  121. PRINT "ROMA"
  122. LOCATE 20, 1
  123. PRINT "TORINO"
  124. LOCATE 22, 1
  125. PRINT "VENEZIA"
  126. LOCATE 24, 1
  127. PRINT "NAZIONALE"
  128. ' setup screen labels for reporting data
  129. LOCATE 2, 50
  130. PRINT "BARI"
  131. LOCATE 4, 50
  132. PRINT "CAGLIARI"
  133. LOCATE 6, 50
  134. PRINT "FIRENZE"
  135. LOCATE 8, 50
  136. PRINT "GENOVA"
  137. LOCATE 10, 50
  138. PRINT "MILANO"
  139. LOCATE 12, 50
  140. PRINT "NAPOLI"
  141. LOCATE 16, 50
  142. PRINT "PALERMO"
  143. LOCATE 18, 50
  144. PRINT "ROMA"
  145. LOCATE 20, 50
  146. PRINT "TORINO"
  147. LOCATE 22, 50
  148. PRINT "VENEZIA"
  149. LOCATE 24, 50
  150. PRINT "NAZIONALE"
  151.  
  152. 'some directions
  153.  
  154. FUNCTION DD$ (number) 'convert a number into a 2 digit string$
  155.     DD$ = RIGHT$("00" + _TRIM$(STR$(number)), 2)
  156.  
  157. FUNCTION diff30in90 (a, b) 'default integers a-z
  158.     DIM hi, lo
  159.     IF a > 90 OR b > 90 OR a < 1 OR b < 1 OR a = b THEN EXIT FUNCTION 'no diff return 0
  160.     IF a > b THEN hi = a: lo = b ELSE hi = b: lo = a
  161.     IF hi - lo = 30 THEN
  162.         diff30in90 = -1
  163.     ELSE
  164.         IF ABS(hi - lo) = 60 THEN diff30in90 = -1
  165.     END IF
  166.  
  167.  
  168.  
  169.  
  170.  


maybe this is what I edit in the beginning

Code: QB64: [Select]
  1. OPTION _EXPLICIT 'for typo's   yep lineMun blah!
  2.  
  3. DEFINT A-Z ' everything is integer unless DIM or suffix
  4. CONST nRows = 11 'rows of 5 data points in each line of fileDat
  5. DIM a AS STRING, count, i, lineNum, lineNum2 ' for file and array access
  6. DIM Q$ '                             for INKEY$
  7. DIM row, col, aPlace, aPlace2 '               for screening Data from a string
  8. DIM rowCnt, x, y, d, rowPlus '       for loading lineDAT() from a file string
  9. DIM lineDAT(1 TO 5, 1 TO nRows) AS INTEGER 'an  array to load from each line from DAT
  10. DIM shiftRight
  11. DIM shiftRight2
  12. shiftRight2 = 65
  13. shiftRight = 15
  14.  
  15. 'count lines in file
  16. OPEN "lotto.dat" FOR INPUT AS #1
  17.     INPUT #1, a
  18.     '          debug check inputs from file
  19.     'PRINT a
  20.     'INPUT " OK enter "; w$
  21.     IF LEN(_TRIM$(a)) THEN count = count + 1 'don't want empty lines _TRIM$ removes spaces or other nonsense
  22.  
  23. 'now we now size of file so ready an array to load file Data
  24. DIM fileDAT(1 TO count) AS STRING
  25. OPEN "lotto.dat" FOR INPUT AS #1
  26. FOR i = 1 TO count
  27.     INPUT #1, a
  28.     IF LEN(_TRIM$(a)) THEN fileDAT(i) = a 'don't want empty lines _TRIM$ removes spaces or other nonsense
  29.  
  30. ' NOW all the data if loaded into fileDAT() array, 480 strings of Lottory data
  31.  
  32. GOSUB labelScreen
  33.  
  34. 'set first line and get a data string from the FileDAT array
  35. lineNum = 1
  36. a = fileDAT(lineNum)
  37. lineNum2 = 1
  38. a = fileDAT(lineNum2)
  39.  
  40.     Q$ = INKEY$
  41.     IF Q$ = "+" THEN lineNum = lineNum + 1
  42.     IF Q$ = "-" THEN lineNum = lineNum - 1
  43.     IF Q$ = CHR$(0) + CHR$(72) THEN lineNum2 = lineNum2 + 1
  44.     IF Q$ = CHR$(0) + CHR$(80) THEN lineNum2 = lineNum2 - 1
  45.     IF lineNum2 > count THEN lineNum2 = 1
  46.     IF lineNum2 < 1 THEN lineNum2 = count
  47.  
  48.     IF lineNum > count THEN lineNum = 1
  49.     IF lineNum < 1 THEN lineNum = count
  50.  
  51.     'get new data line
  52.     a = fileDAT(lineNum)
  53.  
  54.     a = fileDAT(lineNum2)
  55.     'print out the data from the new line
  56.     CLS
  57.     GOSUB labelScreen
  58.     GOSUB screenDataLine
  59.     GOSUB loadLineDAT_Mark30s
  60.     _DISPLAY
  61.     _LIMIT 30
  62.  
  63.  
  64. loadLineDAT_Mark30s: 'this  loads the lineDAT array, so we can sweep through the columes and mark 30's
  65. rowCnt = 1: y = 1
  66. FOR i = 5 TO LEN(a) STEP 2 ' is marking off the start of each data 2 digit integer
  67.     lineDAT(rowCnt, y) = VAL(MID$(a, i, 2)) 'convert data item to integer
  68.     rowCnt = rowCnt + 1 ' increase column if at 6 start new row
  69.     IF rowCnt = 6 THEN y = y + 1: rowCnt = 1
  70. COLOR 9 'blue marker  seacrh through columes for  30's
  71. FOR col = 1 TO 5 'for each of the columes of data
  72.     FOR row = 1 TO 10 'for each of the rows of dat
  73.         FOR rowPlus = row + 1 TO 11 'compare the next rows for diff 30 with current col, row
  74.             IF diff30in90(lineDAT(col, row), lineDAT(col, rowPlus)) THEN
  75.                 LOCATE row * 2, col * 3 - 2 + shiftRight: PRINT DD$(lineDAT(col, row));
  76.                 LOCATE rowPlus * 2, col * 3 - 2 + shiftRight: PRINT DD$(lineDAT(col, rowPlus));
  77.                 '--------------------------------------------------------------------------
  78.  
  79.                 LOCATE row * 2, col * 3 - 2 + shiftRight2: PRINT DD$(lineDAT(col, row));
  80.                 LOCATE rowPlus * 2, col * 3 - 2 + shiftRight2: PRINT DD$(lineDAT(col, rowPlus));
  81.  
  82.             END IF
  83.         NEXT
  84.     NEXT
  85.  
  86.  
  87. screenDataLine:
  88. LOCATE 1, 34
  89. PRINT "estraz.num "; LEFT$(a, 4); "   lineNum:"; STR$(lineNum);
  90. aPlace = 5
  91. FOR row = 1 TO 11
  92.     FOR col = 1 TO 5
  93.         LOCATE row * 2, col * 3 - 2 + shiftRight: PRINT MID$(a, aPlace, 2);
  94.         aPlace = aPlace + 2
  95.     NEXT
  96. '------------------------------------------------------------------------
  97. LOCATE 1, 34
  98. PRINT "estraz.num "; LEFT$(a, 4); "   lineNum:"; STR$(lineNum2);
  99. aPlace = 5
  100. FOR row = 1 TO 11
  101.     FOR col = 1 TO 5
  102.         LOCATE row * 2, col * 3 - 2 + shiftRight2: PRINT MID$(a, aPlace, 2);
  103.         aPlace = aPlace + 2
  104.     NEXT
  105.  
  106.  
  107.  
  108. labelScreen:
  109. ' setup screen labels for reporting data
  110. LOCATE 2, 1
  111. PRINT "BARI"
  112. LOCATE 4, 1
  113. PRINT "CAGLIARI"
  114. LOCATE 6, 1
  115. PRINT "FIRENZE"
  116. LOCATE 8, 1
  117. PRINT "GENOVA"
  118. LOCATE 10, 1
  119. PRINT "MILANO"
  120. LOCATE 12, 1
  121. PRINT "NAPOLI"
  122. LOCATE 16, 1
  123. PRINT "PALERMO"
  124. LOCATE 18, 1
  125. PRINT "ROMA"
  126. LOCATE 20, 1
  127. PRINT "TORINO"
  128. LOCATE 22, 1
  129. PRINT "VENEZIA"
  130. LOCATE 24, 1
  131. PRINT "NAZIONALE"
  132. 'some directions
  133. LOCATE 24, 1
  134. PRINT " + to move on";
  135. LOCATE 25, 16
  136. PRINT "- to back";
  137.  
  138. FUNCTION DD$ (number) 'convert a number into a 2 digit string$
  139.     DD$ = RIGHT$("00" + _TRIM$(STR$(number)), 2)
  140.  
  141. FUNCTION diff30in90 (a, b) 'default integers a-z
  142.     DIM hi, lo
  143.     IF a > 90 OR b > 90 OR a < 1 OR b < 1 OR a = b THEN EXIT FUNCTION 'no diff return 0
  144.     IF a > b THEN hi = a: lo = b ELSE hi = b: lo = a
  145.     IF hi - lo = 30 THEN
  146.         diff30in90 = -1
  147.     ELSE
  148.         IF ABS(hi - lo) = 60 THEN diff30in90 = -1
  149.     END IF
  150.  
  151.  
  152.  
  153.  
  154.  

yes i want to combine my two passions the qb64 and lottery

I want to learn programming well
se avessi solo un'ora per salvare il mondo, passerei 55 minuti per definire bene il problema e 5 a trovare la soluzione

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: help my
« Reply #99 on: July 15, 2020, 08:18:25 pm »
Here is start of problems in Kiara mod of b+ code:
Code: QB64: [Select]
  1.     'get new data line
  2.     a = fileDAT(lineNum)
  3.  
  4.     a = fileDAT(lineNum2)  ' <<<  use a2 for a separate line of data for the right hand set
  5.  

So setup a2 as string and wherever you see "a" distinguish with a2 for the right set of data.

« Last Edit: July 15, 2020, 08:22:20 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: help my
« Reply #100 on: July 15, 2020, 11:11:29 pm »
Here is b+ mod of Kiara mod of b+, two independent screen or page views of lotto data AND a mouse click up or down to shift the data day for each page:
Code: QB64: [Select]
  1. OPTION _EXPLICIT 'for typo's   yep lineMun blah!  b+ mod of kiara mod of b+ 2020-07-15
  2.  
  3. DEFINT A-Z ' everything is integer unless DIM or suffix
  4. CONST nRows = 11 'rows of 5 data points in each line of fileDat
  5. DIM a AS STRING, a2 AS STRING, count, i, lineNum, lineNum2 ' for file and array access
  6. DIM Q$ '                             for INKEY$
  7. DIM row, col, aPlace, aPlace2 '               for screening Data from a string
  8. DIM rowCnt, x, y, d, rowPlus '       for loading lineDAT() from a file string
  9. DIM lineDAT(1 TO 5, 1 TO nRows) AS INTEGER 'an  array to load from each line from DAT
  10. DIM shiftRight
  11. DIM shiftRight2
  12. DIM mb, mx, my, oldmouse ' oldmouse is trick Steve McNeill showed us to get ONE mouse click!
  13. shiftRight2 = 46
  14. shiftRight = 19
  15.  
  16.  
  17. 'count lines in file
  18. OPEN "lotto.dat" FOR INPUT AS #1
  19.     INPUT #1, a
  20.     '          debug check inputs from file
  21.     'PRINT a
  22.     'INPUT " OK enter "; w$
  23.     IF LEN(_TRIM$(a)) THEN count = count + 1 'don't want empty lines _TRIM$ removes spaces or other nonsense
  24.  
  25. 'now we now size of file so ready an array to load file Data
  26. DIM fileDAT(1 TO count) AS STRING
  27. OPEN "lotto.dat" FOR INPUT AS #1
  28. FOR i = 1 TO count
  29.     INPUT #1, a
  30.     IF LEN(_TRIM$(a)) THEN fileDAT(i) = a 'don't want empty lines _TRIM$ removes spaces or other nonsense
  31.  
  32. ' NOW all the data if loaded into fileDAT() array, 480 strings of Lottory data
  33.  
  34. GOSUB labelScreen
  35.  
  36. 'set first line and get a data string from the FileDAT array
  37. lineNum = 1
  38. a = fileDAT(lineNum)
  39. lineNum2 = 1
  40. a2 = fileDAT(lineNum2)
  41.  
  42.     CLS
  43.     Q$ = INKEY$
  44.     IF Q$ = "+" THEN lineNum = lineNum + 1
  45.     IF Q$ = "-" THEN lineNum = lineNum - 1
  46.     IF Q$ = CHR$(0) + CHR$(72) THEN lineNum2 = lineNum2 + 1
  47.     IF Q$ = CHR$(0) + CHR$(80) THEN lineNum2 = lineNum2 - 1
  48.  
  49.     mb = _MOUSEBUTTON(1): mx = _MOUSEX: my = _MOUSEY
  50.     'LOCATE 3, 1: PRINT mx, my
  51.     IF mb AND oldmouse = 0 AND my > 24 THEN ' <<<<<<<<<<<<<<<<<<<<<<<   THANK's  SMcNeill
  52.         '_DELAY .25 '        just one click please!
  53.         IF 17 <= mx AND mx <= 25 THEN lineNum = lineNum + 1
  54.         IF 28 <= mx AND mx <= 37 THEN lineNum = lineNum - 1
  55.         IF 44 <= mx AND mx <= 52 THEN lineNum2 = lineNum2 + 1
  56.         IF 55 <= mx AND mx <= 64 THEN lineNum2 = lineNum2 - 1
  57.     END IF
  58.     oldmouse = _MOUSEBUTTON(1) ' <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<   THANK's  SMcNeill
  59.     IF lineNum2 > count THEN lineNum2 = 1
  60.     IF lineNum2 < 1 THEN lineNum2 = count
  61.  
  62.     IF lineNum > count THEN lineNum = 1
  63.     IF lineNum < 1 THEN lineNum = count
  64.  
  65.     'get new data line
  66.     a = fileDAT(lineNum)
  67.  
  68.     a2 = fileDAT(lineNum2)
  69.     'print out the data from the new line
  70.  
  71.     GOSUB labelScreen
  72.     GOSUB screenDataLine
  73.     GOSUB loadLineDAT_Mark30s
  74.     _DISPLAY
  75.     _LIMIT 30
  76.  
  77. loadLineDAT_Mark30s: 'this  loads the lineDAT array, so we can sweep through the columes and mark 30's
  78. rowCnt = 1: y = 1
  79. FOR i = 5 TO LEN(a) STEP 2 ' is marking off the start of each data 2 digit integer
  80.     lineDAT(rowCnt, y) = VAL(MID$(a, i, 2)) 'convert data item to integer
  81.     rowCnt = rowCnt + 1 ' increase column if at 6 start new row
  82.     IF rowCnt = 6 THEN y = y + 1: rowCnt = 1
  83. COLOR 9 'blue marker  seacrh through columes for  30's
  84. FOR col = 1 TO 5 'for each of the columes of data
  85.     FOR row = 1 TO 10 'for each of the rows of dat
  86.         FOR rowPlus = row + 1 TO 11 'compare the next rows for diff 30 with current col, row
  87.             IF diff30in90(lineDAT(col, row), lineDAT(col, rowPlus)) THEN
  88.                 LOCATE row * 2 + 1, col * 3 - 2 + shiftRight: PRINT DD$(lineDAT(col, row));
  89.                 LOCATE rowPlus * 2 + 1, col * 3 - 2 + shiftRight: PRINT DD$(lineDAT(col, rowPlus));
  90.             END IF
  91.         NEXT
  92.     NEXT
  93. '---------------------------------------------------- right side  a2 data line
  94. rowCnt = 1: y = 1
  95. FOR i = 5 TO LEN(a2) STEP 2 ' is marking off the start of each data 2 digit integer
  96.     lineDAT(rowCnt, y) = VAL(MID$(a2, i, 2)) 'convert data item to integer
  97.     rowCnt = rowCnt + 1 ' increase column if at 6 start new row
  98.     IF rowCnt = 6 THEN y = y + 1: rowCnt = 1
  99. COLOR 9 'blue marker  seacrh through columes for  30's
  100. FOR col = 1 TO 5 'for each of the columes of data
  101.     FOR row = 1 TO 10 'for each of the rows of dat
  102.         FOR rowPlus = row + 1 TO 11 'compare the next rows for diff 30 with current col, row
  103.             IF diff30in90(lineDAT(col, row), lineDAT(col, rowPlus)) THEN
  104.                 LOCATE row * 2 + 1, col * 3 - 2 + shiftRight2: PRINT DD$(lineDAT(col, row));
  105.                 LOCATE rowPlus * 2 + 1, col * 3 - 2 + shiftRight2: PRINT DD$(lineDAT(col, rowPlus));
  106.             END IF
  107.         NEXT
  108.     NEXT
  109.  
  110.  
  111. screenDataLine:
  112. LOCATE 1, 16
  113. PRINT "estraz: "; LEFT$(a, 4); "  line:"; STR$(lineNum);
  114. aPlace = 5
  115. FOR row = 1 TO 11
  116.     FOR col = 1 TO 5
  117.         LOCATE row * 2 + 1, col * 3 - 2 + shiftRight: PRINT MID$(a, aPlace, 2);
  118.         aPlace = aPlace + 2
  119.     NEXT
  120. '-------------------------------------------------- Right side
  121. LOCATE 1, 15 + 43
  122. PRINT "estraz "; LEFT$(a2, 4); "   line:"; STR$(lineNum2); '<<<<<<<<<<<<<<< a2 now
  123. aPlace = 5
  124. FOR row = 1 TO 11
  125.     FOR col = 1 TO 5
  126.         LOCATE row * 2 + 1, col * 3 - 2 + shiftRight2: PRINT MID$(a2, aPlace, 2); '<<<<<<<<<<<<<<< a2 now
  127.         aPlace = aPlace + 2
  128.     NEXT
  129.  
  130. labelScreen:
  131. DIM labels(11) AS STRING ' setup screen labels for reporting data
  132. labels(1) = "BARI"
  133. labels(2) = "CAGLIARI"
  134. labels(3) = "FIRENZE"
  135. labels(4) = "GENOVA"
  136. labels(5) = "MILANO"
  137. labels(6) = "NAPOLI"
  138. labels(7) = "PALERMO"
  139. labels(8) = "ROMA"
  140. labels(9) = "TORINO"
  141. labels(10) = "VENEZIA"
  142. labels(11) = "NAZIONALE"
  143. FOR i = 1 TO 11
  144.     LOCATE i * 2 + 1, 36: PRINT labels(i)
  145. LOCATE 25, 1
  146. PRINT " Fare clic su:  Fino / Up  Giu / Down      Fino / Up  Giu / Down";
  147. '      12345678901234567890123456789012345678901234567890123456789012345678901234567890
  148. '               1         2         3         4         5         6         7         8
  149.  
  150. FUNCTION DD$ (number) 'convert a number into a 2 digit string$
  151.     DD$ = RIGHT$("00" + _TRIM$(STR$(number)), 2)
  152.  
  153. FUNCTION diff30in90 (a, b) 'default integers a-z
  154.     DIM hi, lo
  155.     IF a > 90 OR b > 90 OR a < 1 OR b < 1 OR a = b THEN EXIT FUNCTION 'no diff return 0
  156.     IF a > b THEN hi = a: lo = b ELSE hi = b: lo = a
  157.     IF hi - lo = 30 THEN
  158.         diff30in90 = -1
  159.     ELSE
  160.         IF ABS(hi - lo) = 60 THEN diff30in90 = -1
  161.     END IF
  162.  
  163.  

@Kiara87  Still working on the date thing but we are closer to that model you showed in link.

EDIT: replaced hack _DELAY .25 with Steve McNeill oldmouse trick for getting just one click response.
« Last Edit: July 15, 2020, 11:25:15 pm by bplus »

Offline Kiara87

  • Forum Regular
  • Posts: 164
    • View Profile
Re: help my
« Reply #101 on: July 16, 2020, 04:31:43 am »
the date must be as in the image  --> https://imgur.com/JU9nILf

the draws are 3 times a week

the days are Tuesday Thursday and Saturday
estr. 1465 = Tuesday 6 June 2017
estr. 1466 = Thursday 8 June 2017
estr. 1467 = Saturday 10 June 2017
se avessi solo un'ora per salvare il mondo, passerei 55 minuti per definire bene il problema e 5 a trovare la soluzione

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: help my
« Reply #102 on: July 16, 2020, 11:34:41 am »
That date conversion thing is a thinker! I have to consult my calendar functions, this is like work ;(

Offline Kiara87

  • Forum Regular
  • Posts: 164
    • View Profile
Re: help my
« Reply #103 on: July 16, 2020, 12:18:12 pm »
That date conversion thing is a thinker! I have to consult my calendar functions, this is like work ;(

if you want help you can also ask

😅 :D
se avessi solo un'ora per salvare il mondo, passerei 55 minuti per definire bene il problema e 5 a trovare la soluzione

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: help my
« Reply #104 on: July 16, 2020, 12:38:40 pm »
OK does anybody have a function to convert a lotto number to a day and date?

Hint: Lotto Days are Tues, Thurs, Sat and I assume they don't stop for anything
1465 > = Tues, June 6, 2017
1466 > = Thurs, June 8, 2017
1467 > = Sat, June 10, 2017
...

🤷‍♂️