|
Post by carlos45 on Apr 17, 2024 0:09:58 GMT
Attachments:
|
|
|
Post by carlos45 on Apr 17, 2024 0:14:29 GMT
Here without function _Title "Qbasic64" Screen _NewImage(700, 740, 256) _Delay .25 _ScreenMove 20, 30
Dim terno(60) For i = 1 To 60 terno(i) = 0 Next i dezenas$ = "071940074042153542154042151942154042071935193542193542154042151935071542073540153542071535071940071940071519071542071940071540151935151935354042193540193540" For i = 1 To Len(dezenas$) Step 2 dezena$ = Mid$(dezenas$, i, 2) dezena = Val(dezena$) terno(dezena) = terno(dezena) + 1 Next i For i = 1 To 50 If terno(i) > 0 Then Print "Dez "; TS2$(i); " h "; TS2$(terno(i)); " repetidas" End If Next i Function TS2$ (nn As Long) TS2$ = Right$("00" + LTrim$(Str$(nn)), 2) End Function
Attachments:
|
|
Aaditya Parashar
Junior Member
Just somebody with an abnormal coding routine.
Posts: 95
|
Post by Aaditya Parashar on Apr 17, 2024 4:26:57 GMT
Error on line 9: You need to specify the second argument for the function:
Print i; ContarRepeticoes%(i, dezenas$) And the function should be:
Function ContarRepeticoes%(dez, dezenas$) For I = 1 To Len(dezenas$) Step 2 If Val(Mid$(dezenas$, I, 2)) = dez Then Contar = Contar + 1 Next I ContarRepeticoes = Contar End Function You don't need an array to store the counts.
|
|
|
Post by bplus on Apr 17, 2024 7:56:56 GMT
AP is correct, you don't need array
_Title "carlos code fix" Screen _NewImage(700, 600, 32) _ScreenMove 20, 30
d$ = "071940074042153542154042151942154042071935193542193542154042151935071542073540153542071535071940071940071519071542071940071540151935151935354042193540193540" For i% = 1 To 50 count = ContarRepeticoes%(i%, d$) If count <> 0 Then Print i%, count Next i% Function ContarRepeticoes% (dez, dezenas$) For I% = 1 To Len(dezenas$) Step 2 If Val(Mid$(dezenas$, I%, 2)) = dez Then Contar% = Contar% + 1 Next ContarRepeticoes% = Contar% End Function
also it might good idea NOT to call the function with the same variable names you used to define the function (you only need that in GOSUBs) that is the beauty of functions and subs, once they are working you can use them in any program without worry of matching variable names in main code.
also we are using QB64 and would be good idea not to call anything here Qbasic with or without the 64, QBasic was DOS stuff.
|
|
|
Post by carlos45 on Apr 17, 2024 22:04:17 GMT
Error on line 9: You need to specify the second argument for the function: Print i; ContarRepeticoes%(i, dezenas$) And the function should be: Function ContarRepeticoes%(dez, dezenas$) For I = 1 To Len(dezenas$) Step 2 If Val(Mid$(dezenas$, I, 2)) = dez Then Contar = Contar + 1 Next I ContarRepeticoes = Contar End Function You don't need an array to store the counts. Attachments:
|
|
|
Post by carlos45 on Apr 17, 2024 22:09:52 GMT
Once again, thank you immensely, Bplus. Your example was perfect, just the way I wanted. I will be careful not to use the title 'QBasic' anymore. Thanks for the contribution!" Carlos Attachments:
|
|
|
Post by bplus on Apr 17, 2024 22:52:25 GMT
hi Carlos, as usual my pleasure to be of help when i can. AP thanks also you gave me a head start this morning
|
|
|
Post by carlos45 on Apr 17, 2024 22:56:57 GMT
|
|
|
Post by bplus on Apr 17, 2024 23:59:47 GMT
Declaring variables before using them is good programming practice especially in huge programs where typo can waste tons of time ie use Option _Explicit and force yourself to declare variables first. Besides saving you time from typos it helps keep you mindful of Types.
but no you are not required to declare variables before using them in QB64, either in Main module nor in subroutines.
|
|