本文介绍了生成随机数VBA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试生成一个随机数,并使用标签显示它.这是我的代码:
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
为什么我的标签没有更改为1和2之间的随机数? 3
Why is my label not changing to a random number between 1 & 3
根据评论中的问题更新
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")
推荐答案
Random的值在1到3之间变化,您可以通过运行它来查看,
The value of Random is changing between 1 and 3, you can see by running this,
Dim Random As IntegerRandom = Int((3 * Rnd) + 1)MsgBox Random
Dim Random As IntegerRandom = Int((3 * Rnd) + 1)MsgBox Random
此问题与Label108.Caption = Random有关,我不确定此行在做什么?
This issue is with Label108.Caption = Random, i'm not sure what this line is doing?
这篇关于生成随机数VBA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!