骰子滚子填充TextBox(s)

时间:2015-04-30 05:21:17

标签: vb.net visual-studio-2012

我仍然在学习基础编程,完全脱离Visual Basic 2012 v11。

以下是我难倒的事: 我制作了一个简单的桌面角色扮演角色日志应用程序。 我制作了一个简单的骰子滚轮/“随机数”程序,并将其设置为填充ListBox,每次按下“ROLL”按钮,直到达到最大值6。这很好。

但是,我将我的应用程序更改为与数据库链接,以便为所有玩家等存储简单的角色信息。这意味着我现在每次点击“ROLL”都有单独的数据集TextBox。有人请告诉我最好的方法是每按一次按钮填充一个TextBox,最多点击6次,是吗?

我正在使用一个循环来填充ListBox中的6个条目,并开始填充TextBoxes的思路,但我深夜疲惫的大脑无法找到一种方法来填充一个盒子每个时间而不是每个盒子单次。 谢谢你的帮助!

我的代码:

  Private Sub btnRoll_Click(sender As Object, e As EventArgs) Handles btnRoll.Click
    'Roll a character stat up to 6 and add it to the lisbox
    'D20 is standard die, but stats below 6 are forgiven for this campagin
    Dim Dice As New Random
    Dim DiceRoll As Integer = Dice.Next(6, 20)
    Dim intCount As Integer = 0
    Dim Stat As String = Convert.ToString(DiceRoll)

    Do While intCount < 7

    Loop


End Sub

1 个答案:

答案 0 :(得分:0)

我不相信你已经提供了足够的信息来提供明智的答案。

根据我的理解,您想要获取滚动的结果,并将其输入到多个文本框中的一个(您没有提供多个文本框,但是您希望它在不到6次点击时完成)。

根据不同字段的不同,您可能希望在循环中包含计算,以及指定输出,然后在循环中再次滚动X次:

Do While intcount < 7
    Select Case intcount
        Case 1
            txtBox1 = stat
        Case 2
            txtBox2 = stat
        Case 3
            txtBox3 = stat
        Case 4
            txtBox4 = stat
        Case 5
            txtBox5 = stat
        Case 6
            txtBox6 = stat
        Case Else
        'Nothing if not specified with other arguments. 

    'Roll again
    stat = Convert.ToString(Dice.Next(6,20))

Loop