Author Topic: help my  (Read 19632 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: help my
« Reply #60 on: July 03, 2020, 05:17:30 pm »
@bplus
great job to modularize the code!

I think that this can be a good help to kiara87 to see and to understand the tecnique behind this code.
More modular more flexible!

About italian translator... 6- in top rating 0-10, otherwise D  in english rating.

Thanks @TempodiBasic  But the translations to Italian not so good? They were brought to you by Bing BTW.

Offline Kiara87

  • Forum Regular
  • Posts: 164
Re: help my
« Reply #61 on: July 03, 2020, 07:39:38 pm »
Thank you so much bplus

you are a true master I am seeing techniques never seen before instructions that I didn't even know existed

i'm studying your code so i learn something 

I wanted to change the position where it prints the numbers I want to support them

Code: QB64: [Select]
  1. screenDataLine:
  2. LOCATE 1, 34
  3. PRINT "estraz.num "; LEFT$(a, 4); "   lineNum:"; STR$(lineNum);
  4. aPlace = 5
  5. FOR row = 1 TO 11
  6.     FOR col = 4 TO 8  ' <----- changing this works moves the numbers to the right position '
  7.         LOCATE row * 2, col * 3 - 2: PRINT VAL(MID$(a, aPlace, 2));
  8.         aPlace = aPlace + 2
  9.     NEXT


Code: QB64: [Select]
  1. loadLineDAT_Mark30s: 'this  loads the lineDAT array, so we can sweep through the columes and mark 30's
  2. rowCnt = 1: y = 1
  3. FOR i = 5 TO LEN(a) STEP 2 ' is marking off the start of each data 2 digit integer
  4.     lineDAT(rowCnt, y) = VAL(MID$(a, i, 2)) 'convert data item to integer
  5.     rowCnt = rowCnt + 1 ' increase column if at 6 start new row
  6.     IF rowCnt = 6 THEN y = y + 1: rowCnt = 1
  7. COLOR 10 'blue marker  seacrh through columes for  30's
  8. FOR col = 4 TO 8 'for each of the columes of data    <----I believe this function is for bringing the color over the numbers  but changing this gives me an error
  9.     FOR row = 1 TO 10 'for each of the rows of dat
  10.         FOR rowPlus = row + 1 TO 11 'compare the next rows for diff 30 with current col, row
  11.             IF diff30in90(lineDAT(col, row), lineDAT(col, rowPlus)) THEN
  12.                 LOCATE row * 2, col * 3 - 2: PRINT VAL(DD$(lineDAT(col, row)));
  13.                 LOCATE rowPlus * 2, col * 3 - 2: PRINT VAL(DD$(lineDAT(col, rowPlus)));
  14.             END IF
  15.         NEXT
  16.     NEXT
  17.  

test

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 ' for file and array access
  6. DIM Q$ '                             for INKEY$
  7. DIM row, col, aPlace '               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.  
  11. 'count lines in file
  12. OPEN "lotto.dat" FOR INPUT AS #1
  13.     INPUT #1, a
  14.     '          debug check inputs from file
  15.     'PRINT a
  16.     'INPUT " OK enter "; w$
  17.     IF LEN(_TRIM$(a)) THEN count = count + 1 'don't want empty lines _TRIM$ removes spaces or other nonsense
  18.  
  19. 'now we now size of file so ready an array to load file Data
  20. DIM fileDAT(1 TO count) AS STRING
  21. OPEN "lotto.dat" FOR INPUT AS #1
  22. FOR i = 1 TO count
  23.     INPUT #1, a
  24.     IF LEN(_TRIM$(a)) THEN fileDAT(i) = a 'don't want empty lines _TRIM$ removes spaces or other nonsense
  25.  
  26. ' NOW all the data if loaded into fileDAT() array, 480 strings of Lottory data
  27.  
  28. GOSUB labelScreen
  29.  
  30. 'set first line and get a data string from the FileDAT array
  31. lineNum = 1
  32. a = fileDAT(lineNum)
  33.     Q$ = INKEY$
  34.     IF Q$ = "+" THEN lineNum = lineNum + 1
  35.     IF lineNum > count THEN lineNum = 1
  36.     IF Q$ = "-" THEN lineNum = lineNum - 1
  37.     IF lineNum < 1 THEN lineNum = count
  38.  
  39.     'get new data line
  40.     a = fileDAT(lineNum)
  41.  
  42.     'print out the data from the new line
  43.     CLS
  44.     GOSUB labelScreen
  45.     GOSUB screenDataLine
  46.     GOSUB loadLineDAT_Mark30s
  47.     _DISPLAY
  48.     _LIMIT 30
  49.  
  50.  
  51. loadLineDAT_Mark30s: 'this  loads the lineDAT array, so we can sweep through the columes and mark 30's
  52. rowCnt = 1: y = 1
  53. FOR i = 5 TO LEN(a) STEP 2 ' is marking off the start of each data 2 digit integer
  54.     lineDAT(rowCnt, y) = VAL(MID$(a, i, 2)) 'convert data item to integer
  55.     rowCnt = rowCnt + 1 ' increase column if at 6 start new row
  56.     IF rowCnt = 6 THEN y = y + 1: rowCnt = 1
  57. COLOR 10 'blue marker  seacrh through columes for  30's
  58. FOR col = 4 TO 8 'for each of the columes of data
  59.     FOR row = 1 TO 10 'for each of the rows of dat
  60.         FOR rowPlus = row + 1 TO 11 'compare the next rows for diff 30 with current col, row
  61.             IF diff30in90(lineDAT(col, row), lineDAT(col, rowPlus)) THEN
  62.                 LOCATE row * 2, col * 3 - 2: PRINT VAL(DD$(lineDAT(col, row)));
  63.                 LOCATE rowPlus * 2, col * 3 - 2: PRINT VAL(DD$(lineDAT(col, rowPlus)));
  64.             END IF
  65.         NEXT
  66.     NEXT
  67.  
  68.  
  69. screenDataLine:
  70. LOCATE 1, 34
  71. PRINT "estraz.num "; LEFT$(a, 4); "   lineNum:"; STR$(lineNum);
  72. aPlace = 5
  73. FOR row = 1 TO 11
  74.     FOR col = 4 TO 8
  75.         LOCATE row * 2, col * 3 - 2: PRINT VAL(MID$(a, aPlace, 2));
  76.         aPlace = aPlace + 2
  77.     NEXT
  78.  
  79. '=========================== the above does this ==============================
  80. 'LOCATE 1, 34
  81. 'PRINT "estraz.num "; LEFT$(a, 4); "   lineNum:"; STR$(lineNum)
  82.  
  83. 'REM bari
  84. 'LOCATE 1, 13
  85. 'PRINT VAL(MID$(a, 5, 2))
  86. 'LOCATE 1, 16
  87. 'PRINT VAL(MID$(a, 7, 2))
  88. 'LOCATE 1, 19
  89. 'PRINT VAL(MID$(a, 9, 2))
  90. 'LOCATE 1, 22
  91. 'PRINT VAL(MID$(a, 11, 2))
  92. 'LOCATE 1, 25
  93. 'PRINT VAL(MID$(a, 13, 2))
  94.  
  95. 'REM cagliari
  96. 'LOCATE 3, 13
  97. 'PRINT VAL(MID$(a, 15, 2))
  98. 'LOCATE 3, 16
  99. 'PRINT VAL(MID$(a, 17, 2))
  100. 'LOCATE 3, 19
  101. 'PRINT VAL(MID$(a, 19, 2))
  102. 'LOCATE 3, 22
  103. 'PRINT VAL(MID$(a, 21, 2))
  104. 'LOCATE 3, 25
  105. 'PRINT VAL(MID$(a, 23, 2))
  106.  
  107. 'REM firenze
  108. 'LOCATE 5, 13
  109. 'PRINT VAL(MID$(a, 25, 2))
  110. 'LOCATE 5, 16
  111. 'PRINT VAL(MID$(a, 27, 2))
  112. 'LOCATE 5, 19
  113. 'PRINT VAL(MID$(a, 29, 2))
  114. 'LOCATE 5, 22
  115. 'PRINT VAL(MID$(a, 31, 2))
  116. 'LOCATE 5, 25
  117. 'PRINT VAL(MID$(a, 33, 2))
  118.  
  119. 'REM genova
  120. 'LOCATE 7, 13
  121. 'PRINT VAL(MID$(a, 35, 2))
  122. 'LOCATE 7, 16
  123. 'PRINT VAL(MID$(a, 37, 2))
  124. 'LOCATE 7, 19
  125. 'PRINT VAL(MID$(a, 39, 2))
  126. 'LOCATE 7, 22
  127. 'PRINT VAL(MID$(a, 41, 2))
  128. 'LOCATE 7, 25
  129. 'PRINT VAL(MID$(a, 43, 2))
  130.  
  131. 'REM milano
  132. 'LOCATE 9, 13
  133. 'PRINT VAL(MID$(a, 45, 2))
  134. 'LOCATE 9, 16
  135. 'PRINT VAL(MID$(a, 47, 2))
  136. 'LOCATE 9, 19
  137. 'PRINT VAL(MID$(a, 49, 2))
  138. 'LOCATE 9, 22
  139. 'PRINT VAL(MID$(a, 51, 2))
  140. 'LOCATE 9, 25
  141. 'PRINT VAL(MID$(a, 53, 2))
  142.  
  143. 'REM napoli
  144. 'LOCATE 11, 13
  145. 'PRINT VAL(MID$(a, 55, 2))
  146. 'LOCATE 11, 16
  147. 'PRINT VAL(MID$(a, 57, 2))
  148. 'LOCATE 11, 19
  149. 'PRINT VAL(MID$(a, 59, 2))
  150. 'LOCATE 11, 22
  151. 'PRINT VAL(MID$(a, 61, 2))
  152. 'LOCATE 11, 25
  153. 'PRINT VAL(MID$(a, 63, 2))
  154.  
  155. 'REM palermo
  156. 'LOCATE 13, 13
  157. 'PRINT VAL(MID$(a, 65, 2))
  158. 'LOCATE 13, 16
  159. 'PRINT VAL(MID$(a, 67, 2))
  160. 'LOCATE 13, 19
  161. 'PRINT VAL(MID$(a, 69, 2))
  162. 'LOCATE 13, 22
  163. 'PRINT VAL(MID$(a, 71, 2))
  164. 'LOCATE 13, 25
  165. 'PRINT VAL(MID$(a, 73, 2))
  166.  
  167. 'REM roma
  168. 'LOCATE 15, 13
  169. 'PRINT VAL(MID$(a, 75, 2))
  170. 'LOCATE 15, 16
  171. 'PRINT VAL(MID$(a, 77, 2))
  172. 'LOCATE 15, 19
  173. 'PRINT VAL(MID$(a, 79, 2))
  174. 'LOCATE 15, 22
  175. 'PRINT VAL(MID$(a, 81, 2))
  176. 'LOCATE 15, 25
  177. 'PRINT VAL(MID$(a, 83, 2))
  178.  
  179. 'REM torino
  180. 'LOCATE 17, 13
  181. 'PRINT VAL(MID$(a, 85, 2))
  182. 'LOCATE 17, 16
  183. 'PRINT VAL(MID$(a, 87, 2))
  184. 'LOCATE 17, 19
  185. 'PRINT VAL(MID$(a, 89, 2))
  186. 'LOCATE 17, 22
  187. 'PRINT VAL(MID$(a, 91, 2))
  188. 'LOCATE 17, 25
  189. 'PRINT VAL(MID$(a, 93, 2))
  190.  
  191. 'REM venezia
  192. 'LOCATE 19, 13
  193. 'PRINT VAL(MID$(a, 95, 2))
  194. 'LOCATE 19, 16
  195. 'PRINT VAL(MID$(a, 97, 2))
  196. 'LOCATE 19, 19
  197. 'PRINT VAL(MID$(a, 99, 2))
  198. 'LOCATE 19, 22
  199. 'PRINT VAL(MID$(a, 101, 2))
  200. 'LOCATE 19, 25
  201. 'PRINT VAL(MID$(a, 103, 2))
  202.  
  203. 'REM nazionale
  204. 'LOCATE 21, 13
  205. 'PRINT VAL(MID$(a, 105, 2))
  206. 'LOCATE 21, 16
  207. 'PRINT VAL(MID$(a, 107, 2))
  208. 'LOCATE 21, 19
  209. 'PRINT VAL(MID$(a, 109, 2))
  210. 'LOCATE 21, 22
  211. 'PRINT VAL(MID$(a, 111, 2))
  212. 'LOCATE 21, 25
  213. 'PRINT VAL(MID$(a, 113, 2))
  214. '========================================================================
  215.  
  216. labelScreen:
  217. ' setup screen labels for reporting data
  218. LOCATE 2, 1
  219. PRINT "BARI"
  220. LOCATE 4, 1
  221. PRINT "CAGLIARI"
  222. LOCATE 6, 1
  223. PRINT "FIRENZE"
  224. LOCATE 8, 1
  225. PRINT "GENOVA"
  226. LOCATE 10, 1
  227. PRINT "MILANO"
  228. LOCATE 12, 1
  229. PRINT "NAPOLI"
  230. LOCATE 14, 1
  231. PRINT "PALERMO"
  232. LOCATE 16, 1
  233. PRINT "ROMA"
  234. LOCATE 18, 1
  235. PRINT "TORINO"
  236. LOCATE 20, 1
  237. PRINT "VENEZIA"
  238. LOCATE 22, 1
  239. PRINT "NAZIONALE"
  240. 'some directions
  241. LOCATE 24, 1
  242. PRINT " + to move on";
  243. LOCATE 24, 16
  244. PRINT "- to back";
  245.  
  246. FUNCTION DD$ (number) 'convert a number into a 2 digit string$
  247.     DD$ = RIGHT$("00" + _TRIM$(STR$(number)), 2)
  248.  
  249. FUNCTION diff30in90 (a, b) 'default integers a-z
  250.     DIM hi, lo
  251.     IF a > 90 OR b > 90 OR a < 1 OR b < 1 OR a = b THEN EXIT FUNCTION 'no diff return 0
  252.     IF a > b THEN hi = a: lo = b ELSE hi = b: lo = a
  253.     IF hi - lo = 30 THEN
  254.         diff30in90 = -1
  255.     ELSE
  256.         IF ABS(hi - lo) = 60 THEN diff30in90 = -1
  257.     END IF
  258.  
  259.  
  260.  


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 + ...
Re: help my
« Reply #62 on: July 03, 2020, 07:57:27 pm »
Quote
I wanted to change the position where it prints the numbers I want to support them

The column numbers are aligned to the array numbers, don't change those because they access exact parts of the array lineDAT().

You can shift the numbers over in the print on screen by adding to LOCATE lines, the col part:

It is Locate Row, Col  so maybe Col plus the amount you want to shift right say 20 characters
Set a variable called shiftRight = 20 will move text over 20 characters
Code: QB64: [Select]
  1. FOR col = 1 TO 5 'for each of the columes of data
  2.     FOR row = 1 TO 10 'for each of the rows of dat
  3.         FOR rowPlus = row + 1 TO 11 'compare the next rows for diff 30 with current col, row
  4.             IF diff30in90(lineDAT(col, row), lineDAT(col, rowPlus)) THEN
  5.                 LOCATE row * 2, col * 3 - 2 + shiftRight: PRINT VAL(DD$(lineDAT(col, row)));  '>>>>>the VAL you added defeats the DD$ format
  6.                 LOCATE rowPlus * 2, col * 3 - 2 + shiftRight: PRINT VAL(DD$(lineDAT(col, rowPlus)));'>>>>>the VAL you added defeats the DD$ format
  7.             END IF
  8.         NEXT
  9.     NEXT
  10.  
  11.  

Remember to do it in the other print section also.

Good to fiddle with numbers and maybe break once or twice or 20 times :-))
(Just remember to keep a backup)

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 ' for file and array access
  6. DIM Q$ '                             for INKEY$
  7. DIM row, col, aPlace '               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. shiftRight = 20
  12.  
  13. 'count lines in file
  14. OPEN "lotto.dat" FOR INPUT AS #1
  15.     INPUT #1, a
  16.     '          debug check inputs from file
  17.     'PRINT a
  18.     'INPUT " OK enter "; w$
  19.     IF LEN(_TRIM$(a)) THEN count = count + 1 'don't want empty lines _TRIM$ removes spaces or other nonsense
  20.  
  21. 'now we now size of file so ready an array to load file Data
  22. DIM fileDAT(1 TO count) AS STRING
  23. OPEN "lotto.dat" FOR INPUT AS #1
  24. FOR i = 1 TO count
  25.     INPUT #1, a
  26.     IF LEN(_TRIM$(a)) THEN fileDAT(i) = a 'don't want empty lines _TRIM$ removes spaces or other nonsense
  27.  
  28. ' NOW all the data if loaded into fileDAT() array, 480 strings of Lottory data
  29.  
  30. GOSUB labelScreen
  31.  
  32. 'set first line and get a data string from the FileDAT array
  33. lineNum = 1
  34. a = fileDAT(lineNum)
  35.     Q$ = INKEY$
  36.     IF Q$ = "+" THEN lineNum = lineNum + 1
  37.     IF lineNum > count THEN lineNum = 1
  38.     IF Q$ = "-" THEN lineNum = lineNum - 1
  39.     IF lineNum < 1 THEN lineNum = count
  40.  
  41.     'get new data line
  42.     a = fileDAT(lineNum)
  43.  
  44.     'print out the data from the new line
  45.     CLS
  46.     GOSUB labelScreen
  47.     GOSUB screenDataLine
  48.     GOSUB loadLineDAT_Mark30s
  49.     _DISPLAY
  50.     _LIMIT 30
  51.  
  52.  
  53. loadLineDAT_Mark30s: 'this  loads the lineDAT array, so we can sweep through the columes and mark 30's
  54. rowCnt = 1: y = 1
  55. FOR i = 5 TO LEN(a) STEP 2 ' is marking off the start of each data 2 digit integer
  56.     lineDAT(rowCnt, y) = VAL(MID$(a, i, 2)) 'convert data item to integer
  57.     rowCnt = rowCnt + 1 ' increase column if at 6 start new row
  58.     IF rowCnt = 6 THEN y = y + 1: rowCnt = 1
  59. COLOR 9 'blue marker  seacrh through columes for  30's
  60. FOR col = 1 TO 5 'for each of the columes of data
  61.     FOR row = 1 TO 10 'for each of the rows of dat
  62.         FOR rowPlus = row + 1 TO 11 'compare the next rows for diff 30 with current col, row
  63.             IF diff30in90(lineDAT(col, row), lineDAT(col, rowPlus)) THEN
  64.                 LOCATE row * 2, col * 3 - 2 + shiftRight: PRINT DD$(lineDAT(col, row));
  65.                 LOCATE rowPlus * 2, col * 3 - 2 + shiftRight: PRINT DD$(lineDAT(col, rowPlus));
  66.             END IF
  67.         NEXT
  68.     NEXT
  69.  
  70.  
  71. screenDataLine:
  72. LOCATE 1, 34
  73. PRINT "estraz.num "; LEFT$(a, 4); "   lineNum:"; STR$(lineNum);
  74. aPlace = 5
  75. FOR row = 1 TO 11
  76.     FOR col = 1 TO 5
  77.         LOCATE row * 2, col * 3 - 2 + shiftRight: PRINT MID$(a, aPlace, 2);
  78.         aPlace = aPlace + 2
  79.     NEXT
  80.  
  81. labelScreen:
  82. ' setup screen labels for reporting data
  83. LOCATE 1, 1
  84. PRINT "BARI"
  85. LOCATE 3, 1
  86. PRINT "CAGLIARI"
  87. LOCATE 5, 1
  88. PRINT "FIRENZE"
  89. LOCATE 7, 1
  90. PRINT "GENOVA"
  91. LOCATE 9, 1
  92. PRINT "MILANO"
  93. LOCATE 11, 1
  94. PRINT "NAPOLI"
  95. LOCATE 13, 1
  96. PRINT "PALERMO"
  97. LOCATE 15, 1
  98. PRINT "ROMA"
  99. LOCATE 17, 1
  100. PRINT "TORINO"
  101. LOCATE 19, 1
  102. PRINT "VENEZIA"
  103. LOCATE 21, 1
  104. PRINT "NAZIONALE"
  105. 'some directions
  106. LOCATE 24, 1
  107. PRINT " + to move on";
  108. LOCATE 24, 16
  109. PRINT "- to back";
  110.  
  111. FUNCTION DD$ (number) 'convert a number into a 2 digit string$
  112.     DD$ = RIGHT$("00" + _TRIM$(STR$(number)), 2)
  113.  
  114. FUNCTION diff30in90 (a, b) 'default integers a-z
  115.     DIM hi, lo
  116.     IF a > 90 OR b > 90 OR a < 1 OR b < 1 OR a = b THEN EXIT FUNCTION 'no diff return 0
  117.     IF a > b THEN hi = a: lo = b ELSE hi = b: lo = a
  118.     IF hi - lo = 30 THEN
  119.         diff30in90 = -1
  120.     ELSE
  121.         IF ABS(hi - lo) = 60 THEN diff30in90 = -1
  122.     END IF
  123.  
  124.  
  125.  
« Last Edit: July 03, 2020, 08:18:32 pm by bplus »

Offline Kiara87

  • Forum Regular
  • Posts: 164
Re: help my
« Reply #63 on: July 04, 2020, 09:35:16 am »
many thanks now i try to finish the program thanks you helped me a lot

The column numbers are aligned to the array numbers, don't change those because they access exact parts of the array lineDAT().

You can shift the numbers over in the print on screen by adding to LOCATE lines, the col part:

It is Locate Row, Col  so maybe Col plus the amount you want to shift right say 20 characters
Set a variable called shiftRight = 20 will move text over 20 characters
Code: QB64: [Select]
  1. FOR col = 1 TO 5 'for each of the columes of data
  2.     FOR row = 1 TO 10 'for each of the rows of dat
  3.         FOR rowPlus = row + 1 TO 11 'compare the next rows for diff 30 with current col, row
  4.             IF diff30in90(lineDAT(col, row), lineDAT(col, rowPlus)) THEN
  5.                 LOCATE row * 2, col * 3 - 2 + shiftRight: PRINT VAL(DD$(lineDAT(col, row)));  '>>>>>the VAL you added defeats the DD$ format
  6.                 LOCATE rowPlus * 2, col * 3 - 2 + shiftRight: PRINT VAL(DD$(lineDAT(col, rowPlus)));'>>>>>the VAL you added defeats the DD$ format
  7.             END IF
  8.         NEXT
  9.     NEXT
  10.  
  11.  

Remember to do it in the other print section also.

Good to fiddle with numbers and maybe break once or twice or 20 times :-))
(Just remember to keep a backup)

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 ' for file and array access
  6. DIM Q$ '                             for INKEY$
  7. DIM row, col, aPlace '               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. shiftRight = 20
  12.  
  13. 'count lines in file
  14. OPEN "lotto.dat" FOR INPUT AS #1
  15.     INPUT #1, a
  16.     '          debug check inputs from file
  17.     'PRINT a
  18.     'INPUT " OK enter "; w$
  19.     IF LEN(_TRIM$(a)) THEN count = count + 1 'don't want empty lines _TRIM$ removes spaces or other nonsense
  20.  
  21. 'now we now size of file so ready an array to load file Data
  22. DIM fileDAT(1 TO count) AS STRING
  23. OPEN "lotto.dat" FOR INPUT AS #1
  24. FOR i = 1 TO count
  25.     INPUT #1, a
  26.     IF LEN(_TRIM$(a)) THEN fileDAT(i) = a 'don't want empty lines _TRIM$ removes spaces or other nonsense
  27.  
  28. ' NOW all the data if loaded into fileDAT() array, 480 strings of Lottory data
  29.  
  30. GOSUB labelScreen
  31.  
  32. 'set first line and get a data string from the FileDAT array
  33. lineNum = 1
  34. a = fileDAT(lineNum)
  35.     Q$ = INKEY$
  36.     IF Q$ = "+" THEN lineNum = lineNum + 1
  37.     IF lineNum > count THEN lineNum = 1
  38.     IF Q$ = "-" THEN lineNum = lineNum - 1
  39.     IF lineNum < 1 THEN lineNum = count
  40.  
  41.     'get new data line
  42.     a = fileDAT(lineNum)
  43.  
  44.     'print out the data from the new line
  45.     CLS
  46.     GOSUB labelScreen
  47.     GOSUB screenDataLine
  48.     GOSUB loadLineDAT_Mark30s
  49.     _DISPLAY
  50.     _LIMIT 30
  51.  
  52.  
  53. loadLineDAT_Mark30s: 'this  loads the lineDAT array, so we can sweep through the columes and mark 30's
  54. rowCnt = 1: y = 1
  55. FOR i = 5 TO LEN(a) STEP 2 ' is marking off the start of each data 2 digit integer
  56.     lineDAT(rowCnt, y) = VAL(MID$(a, i, 2)) 'convert data item to integer
  57.     rowCnt = rowCnt + 1 ' increase column if at 6 start new row
  58.     IF rowCnt = 6 THEN y = y + 1: rowCnt = 1
  59. COLOR 9 'blue marker  seacrh through columes for  30's
  60. FOR col = 1 TO 5 'for each of the columes of data
  61.     FOR row = 1 TO 10 'for each of the rows of dat
  62.         FOR rowPlus = row + 1 TO 11 'compare the next rows for diff 30 with current col, row
  63.             IF diff30in90(lineDAT(col, row), lineDAT(col, rowPlus)) THEN
  64.                 LOCATE row * 2, col * 3 - 2 + shiftRight: PRINT DD$(lineDAT(col, row));
  65.                 LOCATE rowPlus * 2, col * 3 - 2 + shiftRight: PRINT DD$(lineDAT(col, rowPlus));
  66.             END IF
  67.         NEXT
  68.     NEXT
  69.  
  70.  
  71. screenDataLine:
  72. LOCATE 1, 34
  73. PRINT "estraz.num "; LEFT$(a, 4); "   lineNum:"; STR$(lineNum);
  74. aPlace = 5
  75. FOR row = 1 TO 11
  76.     FOR col = 1 TO 5
  77.         LOCATE row * 2, col * 3 - 2 + shiftRight: PRINT MID$(a, aPlace, 2);
  78.         aPlace = aPlace + 2
  79.     NEXT
  80.  
  81. labelScreen:
  82. ' setup screen labels for reporting data
  83. LOCATE 1, 1
  84. PRINT "BARI"
  85. LOCATE 3, 1
  86. PRINT "CAGLIARI"
  87. LOCATE 5, 1
  88. PRINT "FIRENZE"
  89. LOCATE 7, 1
  90. PRINT "GENOVA"
  91. LOCATE 9, 1
  92. PRINT "MILANO"
  93. LOCATE 11, 1
  94. PRINT "NAPOLI"
  95. LOCATE 13, 1
  96. PRINT "PALERMO"
  97. LOCATE 15, 1
  98. PRINT "ROMA"
  99. LOCATE 17, 1
  100. PRINT "TORINO"
  101. LOCATE 19, 1
  102. PRINT "VENEZIA"
  103. LOCATE 21, 1
  104. PRINT "NAZIONALE"
  105. 'some directions
  106. LOCATE 24, 1
  107. PRINT " + to move on";
  108. LOCATE 24, 16
  109. PRINT "- to back";
  110.  
  111. FUNCTION DD$ (number) 'convert a number into a 2 digit string$
  112.     DD$ = RIGHT$("00" + _TRIM$(STR$(number)), 2)
  113.  
  114. FUNCTION diff30in90 (a, b) 'default integers a-z
  115.     DIM hi, lo
  116.     IF a > 90 OR b > 90 OR a < 1 OR b < 1 OR a = b THEN EXIT FUNCTION 'no diff return 0
  117.     IF a > b THEN hi = a: lo = b ELSE hi = b: lo = a
  118.     IF hi - lo = 30 THEN
  119.         diff30in90 = -1
  120.     ELSE
  121.         IF ABS(hi - lo) = 60 THEN diff30in90 = -1
  122.     END IF
  123.  
  124.  
  125.  
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 + ...
Re: help my
« Reply #64 on: July 04, 2020, 12:28:41 pm »
@Kiara87

So I took numbers in string form and converted them to integers when loading the lineDAT() array because it made it easier to compare numbers and run the diff30in90 FUNCTION on them but to print them again from the array, I had to convert them back to strings.

Printing numbers on highly formatted screen is usually a nightmare without some format function to convert them to strings you have more control over.

The DD$ function took any positive number < 100 and made sure 1 digit numbers were aligned on right side with 0's padding (on left) and 0 is presented as "00" (if that should ever come up). I thought 0 padding good for displaying lottery numbers.

You could also pad with spaces instead but have to say
if number = 0 then myNumberFormat$ = " 0"

Alternate pad with spaces, assuming positive numbers for number 0 <= number < 100
Code: QB64: [Select]
  1. FUNCTION DD$ (number) 'convert a number into a 2 digit string$
  2.     IF number = 0 THEN DD$ = " 0" ELSE DD$ = RIGHT$("  " + _TRIM$(STR$(number)), 2)
I better test that...

Update: OK this works fine too:
Code: QB64: [Select]
  1. FUNCTION DD$ (number) 'convert a number into a 2 digit string$
  2.     DD$ = RIGHT$("  " + _TRIM$(STR$(number)), 2)

« Last Edit: July 04, 2020, 12:54:13 pm by bplus »

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
Re: help my
« Reply #65 on: July 04, 2020, 08:06:36 pm »
example of program planning   [ You are not allowed to view this attachment ]  
Programming isn't difficult, only it's  consuming time and coffee

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
Re: help my
« Reply #66 on: July 05, 2020, 09:37:59 pm »
@Kiara87
Ciao
ecco una versione del programma seguendo le vaghe indicazioni che hai fornito in questo thread.

1. è una versione che usa una sola stringa per caricare il file in memoria e poi analizzarlo.
2. esegue l'operazione sul file che hai fornito quindi cambiando file (lunghezza o tipo di dati registrati dentro) va adattato
3. ho seguito le impostazioni di Bplus usando i GOSUB più facili da comprendere e usare rispetto alle SUB e alle FUNCTION
ecco il codice sorgente in QB64
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 reosso
  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. ' il ciclo DO...LOOP UNTIL condizione e' un modo piu' moderno
  24. ' rispetto a Etichetta: .... IF condizione GOTO Etichetta
  25.     ' prende l'input dell'utente
  26.     z$ = UCASE$(INKEY$) ' Z$ mantiene il maiuscolo di Inkey$
  27.     GOSUB MostraRuote ' scrive il nome delle ruote del lotto
  28.     GOSUB MostraEstratti
  29.  
  30. LOOP UNTIL z$ = "Q"
  31.  
  32.  
  33. END ' indica la fine logica del programma
  34.  
  35.  
  36. '-----------------------AREA sottoprogrammi /SUBroutines
  37.  
  38. ' questa etichetta /label indica il punto di inizio
  39. ' del sottoprogramma (SUBroutine) LeggiFile scritto con vecchio stile GOSUB
  40. ' che usa una etichetta/label e un RETURN per riprendere da dove si era interotto
  41. ' nota1: un metodo ancora piu' antico e' il salto con GOTO
  42. '        che richiede una seconda etichetta per ritornare nel MAIN o programma principale
  43. ' nota2: un metodo migliore e' SUB nomeroutine....END SUB
  44. '        perche' permette la localizzazione delle variabili
  45. LeggiFile:
  46. 'se non trova lotto.dat segnala l'errore a video e termina il programma
  47. IF NOT _FILEEXISTS("lotto.dat") THEN PRINT "File non trovato": END
  48. ' apre il file lotto.dat per leggere in maniera sequenziale i dati
  49. OPEN "lotto.dat" FOR INPUT AS #1
  50. a = SPACE$(LOF(1)) ' riempe la variabile a di spazi fino alla grandezza in byte del file aperto
  51. INPUT #1, a ' legge con una unica operazione il file e lo pone nella variabiel a
  52. CLOSE #1 ' chiude il file appena letto
  53. ' indica il termine della SUBroutine LeggiFile
  54. ' e RITORNA alla riga di codice successiva al salto GOSUB
  55.  
  56. 'seconda SUBroutine /sottoprogramma
  57. MostraRuote:
  58. COLOR 7, 6
  59. LOCATE 1, 1
  60. PRINT "BARI"
  61. LOCATE 3, 1
  62. PRINT "CAGLIARI"
  63. LOCATE 5, 1
  64. PRINT "FIRENZE"
  65. LOCATE 7, 1
  66. PRINT "GENOVA"
  67. LOCATE 9, 1
  68. PRINT "MILANO"
  69. LOCATE 11, 1
  70. PRINT "NAPOLI"
  71. LOCATE 13, 1
  72. PRINT "PALERMO"
  73. LOCATE 15, 1
  74. PRINT "ROMA"
  75. LOCATE 17, 1
  76. PRINT "TORINO"
  77. LOCATE 19, 1
  78. PRINT "VENEZIA"
  79. LOCATE 21, 1
  80. PRINT "NAZIONALE"
  81. LOCATE 23, 1
  82. PRINT "premi q per terminare"
  83.  
  84. ' indica il termine della SUBroutine MostraRuote
  85. ' e RITORNA alla riga di codice successiva al salto GOSUB
  86.  
  87. 'terzo sottoprogramma o SUBroutine
  88. MostraEstratti:
  89.  
  90. ' le prime 4 cifre sembrano essere in numero della estrazione
  91. LOCATE 1, 40
  92. PRINT "estraz.num "; LEFT$(a, 4)
  93.  
  94. y = 13 ' prima posizione per il carattere da stampare
  95. FOR x = 1 TO 5 STEP 1 ' questo ciclo   FOR è di 5 perche' lo e' il tuo esempio
  96.     FOR V = Bari TO Nazionale ' per tutte le ruote
  97.         'posiziona il cursore
  98.         LOCATE (V * 2) - 1, y
  99.         ' verifica la condizione + o - 30
  100.         IF (V > 1) AND ABS((VAL(MID$(a, (V - 2) * 10 + 5 + ((x - 1) * 2), Cifra))) - (VAL(MID$(a, (V - 1) * 10 + 5 + ((x - 1) * 2), Cifra)))) = 30 THEN COLOR 4, 1 ELSE COLOR 15, 0
  101.         ' scrive il numero estratto
  102.         PRINT VAL(MID$(a, (V - 1) * 10 + 5 + ((x - 1) * 2), Cifra)); " ";
  103.     NEXT V
  104.     y = POS(0)
  105. ' indica il termine della SUBroutine MostraEstratti
  106. ' e RITORNA alla riga di codice successiva al salto GOSUB

@bplus
I have written this code to give an impulse to kiara87 to come nearer to programming world. The only goal has been to give a simple code with more comments into her native language because it seems that kiara87 has not so skills for english at this moment and she is newborn to programming world.
Programming isn't difficult, only it's  consuming time and coffee

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: help my
« Reply #67 on: July 05, 2020, 11:10:32 pm »
@TempodiBasic

Well I hope your Italian is better than my English ;-))

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
Re: help my
« Reply #68 on: July 06, 2020, 12:34:19 pm »
@bplus
Also I hope so! :-))
Programming isn't difficult, only it's  consuming time and coffee

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
Re: help my
« Reply #69 on: July 06, 2020, 01:18:10 pm »
@Kiara87
Salve, benvenuta nella community di QB64!

Usando il tuo lotto.dat io ho questo output allo schermo
  [ You are not allowed to view this attachment ]  

Quindi in questo output non va bene che è evidenziato solo il 41 ma deve essere evidenziato anche il 71.... non era molto chiara questa caratteristica ma non ci vuole molto per adattare il codice che ti ho postato.....il problema per me è che non era per niente chiaro che il confronto va fatto per qualsiasi elemento di una estrazione versus qualsiasi altro elemento della stessa estrazione... come mostri qui https://imgur.com/YalTULO

in tal caso è bene usare un algoritmo leggermente differente anche senza array. Un po' di immaginazione da parte tua e troverai facilmente la strada. Programmare è trovare soluzioni,ma la vera difficoltà è definire bene il problema e il risultato che si vuole ottenere.
Ma come avevo detto all'inizio senza specifiche chiare da parte tua con un progetto tipo pseudocodice o flowchart o altro ancora che non tralascia alcun dettaglio è solo tempo perso.
In quanto ricevi feedback che non ti sono utili e ti possono portare fuori strada invece di aiutarti e nel frattempo chi risponde alle tue richieste usa tempo ed energie per elaborare risposte non efficaci.
Prima progettare, poi scrivere codice.

Good Luck!


@bplus
Yes man, your look is more insightful than mine! :-))
« Last Edit: July 06, 2020, 01:23:17 pm by TempodiBasic »
Programming isn't difficult, only it's  consuming time and coffee

Offline Kiara87

  • Forum Regular
  • Posts: 164
Re: help my
« Reply #70 on: July 08, 2020, 04:38:39 pm »
@TempodiBasic  and bplus
siete bravissimi tutti e due

you are both very good


ps:  vi invidio


I envy you


non so se google traduttore traduce bene questa parola in inglese


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 + ...
Re: help my
« Reply #71 on: July 08, 2020, 07:17:36 pm »
Hi @Kiara87

Still practicing with lottery example? Have you tried arrays on anything else?

Offline Kiara87

  • Forum Regular
  • Posts: 164
Re: help my
« Reply #72 on: July 09, 2020, 09:48:30 am »

I was trying to finish the program but I find myself with many difficulties I try not to give up but I see programming difficult
maybe I need a master as good as you
only that I don't understand English
I think my problem is to understand the programming logic I mean how can a programmer think
how to compose all the instructions to create the program

I won't give up
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 + ...
Re: help my
« Reply #73 on: July 09, 2020, 11:30:29 am »
It is step by step logic. I play Sudoku allot to practice step by step logic frame of mind.

If get stuck, try practice with simpler examples of problem.

If you find yourself repeating steps over and over, you probably have a subroutine, look for the one or two variables that change each repetition.

Quote
I won't give up


Yes but do give up on the way that isn't working ;-))

Offline Kiara87

  • Forum Regular
  • Posts: 164
Re: help my
« Reply #74 on: July 09, 2020, 04:54:24 pm »
with this game you learn to program  --> https://www.sudoku-it.com/

other people have also told me with  --> Torre de Hanoi 
source 
&t=1447s

these two games teach programming

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