Replace random

Gigatron

Member
Licensed User
Longtime User
Hi all


I have a little problem and need help please,



B4X:
Sub bt1_Click
    tirage1
End Sub

Sub tirage1
   resa=Rnd(1,50)
   lba.Text=resa
   tirage2
End Sub

Sub tirage2
   resb=Rnd(1,50)
   lbb.Text=resb
     If resb<>resa Then 
     tirage3
     Else
      tirage2
     End If
End Sub

Sub tirage3
   
   resc=Rnd(1,50)
   lbc.Text=resc
   
      If resc<>resb AND resc<>resa Then
       tirageok
       Else
       tirage3
       End If
End Sub

Sub tirageok
   resultlbl.Text="TIRAGES OK"
End Sub

Sub btreplace_Click
   storenombres.AddAll(Array As Int(resa,resb,resc))
      
   button1.text=resa
   button2.text=resb
   button3.text=resc   
End Sub

As you can see, When i click on replace random, i would like to replace the 3 generated numbers in different place .

Like in this exemple bt1=17 bt2=12 bt3=24, i would like numbers changing place.

Thanks in advance
 

Gigatron

Member
Licensed User
Longtime User
I have add this code for swapping numbers on buttons, but something wrong ! :BangHead:

Finaly i found the solution, the reason was Empty text on buttons, you can not compare empty text i think .

Thanks all B4android ... to their helps

B4X:
Sub btreplace_Click
   storenombres.Initialize
   storenombres.AddAll(Array As Int(resa,resb,resc))
   rdgen=Rnd(0,3)
      
   replace1
End Sub

Sub replace1
   rdgen=Rnd(0,3)
   button1.Text=storenombres.Get(rdgen)
   replace2
End Sub

Sub replace2
   rdgen=Rnd(0,3)
   button2.Text=storenombres.Get(rdgen)
   
   If button1.Text<>button2.Text Then
   button2.Text=storenombres.Get(rdgen)
   replace3
   Else
   replace2
   End If
End Sub

Sub replace3
   rdgen=Rnd(0,3)
   button3.Text=storenombres.Get(rdgen)
   
   If button3.Text<>button2.Text AND button3.Text<>button1.Text Then
   button3.Text=storenombres.Get(rdgen)
   resultlbl.Text="Replacement OK"
   Else
   replace3
   End If
   
End Sub
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…