Generate random number VBA [closed]

2019-03-07 07:47发布

问题:

I am trying to generate a random number and display it using a label. This is my code:

    Dim Random As Integer
Random = Int((3 * Rnd) + 1)
Label108.Caption = Random

Why is my label not changing to a random number between 1 & 3

UPDATED AS PER QUESTION IN COMMENTS

Private Sub Form_Load()
    Dim Random As Integer
Random = Int((3 * Rnd) + 1)
Label108.Caption = Random

Label8.Caption = Format(Date, "dddd dd mmmm yyyy")
Label14.Caption = Environ("username")

回答1:

The value of Random is changing between 1 and 3, you can see by running this,

Dim Random As Integer Random = Int((3 * Rnd) + 1) MsgBox Random

This issue is with Label108.Caption = Random, i'm not sure what this line is doing?