FOR/NEXT loop with variables/ solved!

Post

Posted
Rating:
#1 (In Topic #831)
Trainee
 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

Image

(Click to enlarge)

Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Enthusiast
PJBlack is in the usergroup ‘Enthusiast’
START.Value ... END.Value ???
Online now: No Back to the top

Post

Posted
Rating:
#3
Trainee
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 ….
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Guru
cogier is in the usergroup ‘Guru’
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: -
Attachment

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: -

Code (gambas)

  1.  For iLoop = 0 To 20
  2.     If iLoop = 5 Then Exit
  3.   Next
  4.   Print iLoop

The loop will only ever get to 5 and the Print statement will print 5.
Online now: No Back to the top

Post

Posted
Rating:
#5
Trainee
 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 …..
Online now: No Back to the top
1 guest and 0 members have just viewed this.