I have code:
Dim i As Integer
---------------------------
Private Sub cmd1_Click()
Randomize
i = Int(20 * Rnd())
Label1.Caption = i
End Sub
---------------------------
What code should I add more to show "i" not the same number?
Please someone help me!
Thanks!

seyha

If you want to generate a different number on every click you could do something like this:

Make an array of booleans.

You would have the array the size of the possible random numbers and each time you select a number you would enter a loop that loops until you found an unselected number:

//you should rename the var you use for your random number to randomNum
//or something more descriptive

Do

//generate your number randomNum

//check if yourArray(randomNum-1) equals false
//if condition met you change the value of yourArray(randomNum-1) to true
//(to know it is selected already)

Loop While ***condition***
//your condition would be while yourArray(randomNum-1) equals false

//you finish it off by doing your desired code (Label1.Caption = randomNum)

Belama,

While any insight that you can offer would be greatly appreciated, this thread is designated for Visual Basic, While your code is PHP, and will not work in a VB IDE ;)

Theres no PHP code. I just put the PHP tags to see some colors. If its too confusing, I wont do it anymore.

And theres not much code to let the person do most of the work.

Mat

Yeah, You're right. I was checking the comments (// and not ') so I immediately thought it was. Sorry for skimming the post (that's what I get) :(

I have code:
Dim i As Integer
---------------------------
Private Sub cmd1_Click()
Randomize
i = Int(20 * Rnd())
Label1.Caption = i
End Sub
---------------------------
What code should I add more to show "i" not the same number?
Please someone help me!
Thanks!

seyha

try this code

Dim i As Integer
Dim existNum As String

Private Sub Command1_Click()

Randomize
i = Int(20 * Rnd())

If InStr(1, existNum, ("," & i)) > 0 Then
    Command1_Click
Else
    Label1.Caption = i
    existNum = existNum & "," & i
    Label2.Caption = existNum
End If

End Sub

hope this what you looking for :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.