Page 1 of 1

FOR/NEXT loop with variables/ solved!

Posted: Tuesday 15th March 2022 5:16pm
by pentilisea
Dear Friends,
as my logic synapses aparently having gone on holidays, I'm stuck with 2 issues.

First:
With a For/Next loop like

For i = ListBox1.count - 1 DownTo ListBox1.count - 180

I want with ValueBoxes labeled START and END to have the user define the ListBox.Count Start-and End-Numbers. I tried to replace -1 and -180 with Integer variables - like:

For i = ListBox1.count - START DownTo ListBox1.count - END

or - leave the loop alone, if the ValueBoxes are "" or empty ...

I got nowhere ... String-Variables also not accepted.

********************************************************

Second:
While the For/Next loop is running through the items of Listbox1 (a list - about 200 items - of Numbers from 0 to 36), it produces "loss" or "win" and a "balance" all of thouse listed in further ListBoxes regarding to thier variables:

loss
totloss
win
totalwin
balance

Works pretty well and matches manual test/control on a spread sheet.
Now I want to catch the trends - as it does not make sense to further bet on a down trend unless a upward trend appears again.

I got around it by limiting betting to 6 or 9 loops/coups. It would be smart, if bets only start after 3 consecutive wins or are not further done after 3 consecutive (excuse spelling) losses.

******************************************************

I'm attaching a screenshot but also could add the code for further understanding (if you prefer some entertainment with my humptydumpty coding).

Would appreciate some hints. Your hints with a previous issue where excellent ...

Well and Third:
How do I leave a FOR/NEXT loop if a condition is reached whithout closing the application? Stop und Exit ? or just Form1.Show? ....

Klaus

Re: FOR/NEXT loop with variables

Posted: Tuesday 15th March 2022 5:42pm
by PJBlack
START.Value ... END.Value ???

Re: FOR/NEXT loop with variables

Posted: Wednesday 16th March 2022 9:29am
by pentilisea
Hi,
START and END values are set by user via 2 ValueBoxes. The Count of ListBox1 is displayed and normally between 150 and 250 items in the list. So, the user wants run a test via button TWO-UP say from 100 to 150, so 100 would be entered in Valuebox START und 150 in ValueBox END.

Important to know that the Numbers/Items in ListBox1 are counted from last Item. Last number (count -1) is displayed and if the bet is = the number (count-2) following Last number, called Prenumber, then a win of 35 is added, last number deleted from list and Prenumber becomes Last number.

So the value of START =100 will represent ListBox1.Count - 100 and END = 150 ListBox1.Count -150 ....

My problem ist how to assign 2 variables START and END and getting thier values into the FOR/NEXT loop.

For i = ListBox1.count - 1 DownTo ListBox1.count - 180

so count-1 would be replaced with count -100 and count -180 would be replaced with count-150 ....

Re: FOR/NEXT loop with variables

Posted: Wednesday 16th March 2022 4:30pm
by cogier
We may need to see the code to fully understand what you are trying to do. Anyway, here is my response:-
First:
With a For/Next loop like

For i = ListBox1.count - 1 DownTo ListBox1.count - 180
Have a look at this code: -
NewTest-0.0.1.tar.gz
(23.21 KiB) Downloaded 168 times
Second:
While the For/Next loop is running through the items of Listbox1 (a list - about 200 items - of Numbers from 0 to 36), it produces "loss" or "win" and a "balance" all of thouse listed in further ListBoxes regarding to thier variables:
Consider using arrays to store the data. An Integer array could hold ID, Total Wins, Total losses: - IDArray = [24, 2, 3]
Well and Third:
How do I leave a FOR/NEXT loop if a condition is reached whithout closing the application? Stop und Exit ? or just Form1.Show? ....
You can use Exit to leave a For Next loop at any time. Consider the following code: -
 For iLoop = 0 To 20
    If iLoop = 5 Then Exit
  Next
  Print iLoop
The loop will only ever get to 5 and the Print statement will print 5.

Re: FOR/NEXT loop with variables

Posted: Thursday 17th March 2022 9:35am
by pentilisea
Dear Cogler,
as always thanks so much for the spot on help. Often I'm spinning around the correct solution and simply not getting the syntax right.
Well, keeing trying and inching foreward .....