vba 在 Visual Basic for Windows Phone 7 中轻松生成随机数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13546823/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 18:35:23  来源:igfitidea点击:

Easily generate random number in Visual Basic for Windows Phone 7

visual-studio-2010windows-phone-7vbarandomnumbers

提问by Mr. Nobody

How can I get a random number (1-6) Using Visual Basic for Windows Phone? Everything I have tried already has resulted in errors. Here's an example of some code that has been producing errors:

如何使用 Visual Basic for Windows Phone 获取随机数 (1-6)?我已经尝试过的一切都导致了错误。下面是一些产生错误的代码示例:

Randomize()
Dim randnum As Integer = CInt(Int((6 * Rnd()) + 1))

"'Randomize' is not declared. Function has moved to the 'Microsoft.VisualBasic' namespace." "'Int' is not declared. It may be inaccessible due to its protection level." "'Rnd' is not declared. Function has moved to the 'Microsoft.VisualBasic' namespace."

“未声明‘Randomize’。函数已移至‘Microsoft.VisualBasic’命名空间。” “'Int' 未声明。由于其保护级别,它可能无法访问。” “未声明‘Rnd’。函数已移至‘Microsoft.VisualBasic’命名空间。”

What do I need to do? The same code works fine in Visual Basic. Thanks.

我需要做什么?相同的代码在 Visual Basic 中运行良好。谢谢。

回答by igrimpe

The RandomClass is supported in Phone 7.x

Random班在电话7.x的支持

    Dim r As New Random
    Dim From1to6 = r.Next(1, 7)