I currently Have this code in VB6.
Option Explicit
Dim RandomNum As Integer
Private Sub Form_Load()
randomize
Label1.Caption = RandomNum = Int((Rnd * 10) + 1)
End Sub
I currently Have this code in VB6.
Option Explicit
Dim RandomNum As Integer
Private Sub Form_Load()
randomize
Label1.Caption = RandomNum = Int((Rnd * 10) + 1)
End Sub
Here is the answer by #steven-doggart.
"In VB6, you need to initially seed the random number generator using the Randomize
function. Then, to generate a random number, you must use the Rnd
function, for instance.."
You're not assigning the random value to your variable or the label correctly.
Change:
Label1.Caption = RandomNum = Int((Rnd * 10) + 1)
To:
RandomNum = Int((Rnd * 10) + 1)
If Random >= 1 And RandomNum <=3 Then
Label1.Caption = "Option1"
Else
Label1.Caption = "Option2"
End If
You can also look into using a Select Case
statement.
I have this function for randomizing with limits :) Hope this may help you also.
Public Function Random(Upper As Integer, Lower As Integer) As Integer
Randomize
Random = Int(Upper * Rnd() + Lower)
End Function