Android Question Why the button is only doing an action once? Using Integer and random

mohdsaks

Member
Licensed User
Longtime User
Dim num1 As Int = Rnd(1,3)

If num1 = 1 Then
lbl_body.Text = "hand"
Else
lbl_body.Text = "leg"
End If

This is my code...And the code is written inside button1_click...when I run the program it worked amazingly but when I click once it appears but then when I click again and again and again the value doesnt change??


Could this be a silly question, does it have to do with activity must be refreshed or Im using the random variable in a wrong way??

Please help!!
 

mohdsaks

Member
Licensed User
Longtime User
Your code works well! Try to click at least 10 times


I tried that many times, it didnt work it just stays the same result from first click no matter how many times I click again and again and again!!

I even tried putting the same code on a different subroutine and call it at the begining of the button click which also didnt work!!
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Looking at the code, I see no errors.

I even tried it and it works!

If you want, post your entire code
 
Upvote 0

mohdsaks

Member
Licensed User
Longtime User
Your code works well! Try to click at least 10 times


I solved it as it turns out only defining the variable inside the button
Looking at the code, I see no errors.

I even tried it and it works!

If you want, post your entire code


I solved it my friend!! Thnks alot Luca as it turns out the problem is that I defined the variable in the process globals when I should have added it into the button click event.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
It's because you don't just define the var, but "set" its value at same time.
I advice to avoid that kind of statement, always.

I'm glad you've solved
 
Upvote 0
Top