挑选随机报价放入标签 [英] Picking Random Quote to put into Label
问题描述
我是编程(高中)的新手,需要一些帮助。是的,这是一项学校作业,但我不只是像大多数人一样寻找副本和粘贴答案(我知道你们必须听到这个很多)。
I'm new to programming (in high school) and need some help on this. Yes, this is a school assignment, but I'm not just looking for a copy and paste answer like most (I know you guys must hear this alot).
我正在尝试每次按下按钮都会让标签显示出侮辱。
I'm trying to make the label show an insult every time I press the button.
这是我到目前为止的代码,但每次尝试都会给我一个错误。有人可以解释为什么这不起作用?我的语法是否关闭?
This is the code I have so far, but it gives me an error every time I try. Can someone explain why this doesn't work? Is my syntax just off?
推荐答案
您好
好尝试但略有不正确。
我的建议:
*
在Form Load事件中。
In the Form Load event.
使用所有 Insults 构建一个List(Of String)。
Build a List(Of String) with all the Insults.
首先声明List - 示例Dim Insults as New List(Of String)
First declare the List - example Dim Insults as New List(Of String)
其次,添加字符串 - 示例Insults.Add("让我们尽可能少地见面") - 重复每个侮辱。
Secondly, add the strings - example Insults.Add("Lets meet as little as we can") - repeat for each Insult.
*
在类级别声明一个随机(整数)。
Declare a random (Integer) at Class level.
示例:
Dim rand As New Random
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'等..............
' etc ..............
*
在按钮点击事件中。
选择0(零)到列表大小范围内的新随机数。示例Dim r as Integer = rand.Next(0,Insults.Count)
Choose a new random number within the range of 0 (zero) to the List size. Example Dim r as Integer = rand.Next(0,Insults.Count)
从列表中获取随机项:
Dim s as String =侮辱(r)
Dim s as String = Insults(r)
*
在标签中找到侮辱:
Label1.Text = s
这篇关于挑选随机报价放入标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!