Generate random number VBA [closed]

余生颓废 提交于 2019-12-20 07:58:14

问题


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?



来源:https://stackoverflow.com/questions/40239356/generate-random-number-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!