Random Numbers and Adding the Random Numbers Generated

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PureCoffee
    New Member
    • Mar 2010
    • 1

    #1

    Random Numbers and Adding the Random Numbers Generated

    So here is some code but I can't get past the generation. I would like to add whatever randomely generated numbers are shown in each "private sub".

    Obviously I am a NOOB to VB but I rather enjoy the challenges. This has me stumped...

    Can someone Please help?
    Thanks,
    PureCoffee

    Public Class Form1

    Private Sub btndeal_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles btndeal.Click
    Randomize()

    Me.lblRandNum1. Text = CStr(CInt(10 * Rnd() + 1))
    Me.lblRandNum2. Text = CStr(CInt(10 * Rnd() + 1))

    End Sub

    Private Sub btndraw_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles btndraw.Click


    Me.lblRandNum3. Text = CStr(CInt(10 * Rnd()) + 1)

    End Sub

    Private Sub btncheckscore_C lick(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles btncheckscore.C lick


    Randomize()
    Me.lblRandNum4. Text = CStr(CInt(10 * Rnd() + 1))
    Me.lblRandNum5. Text = CStr(CInt(10 * Rnd() + 1))
    Me.lblRandNum6. Text = CStr(CInt(10 * Rnd() + 1))


    lblpscore.Text = CStr(CInt(lblRa ndNum1.Text + lblRandNum2.Tex t))

    ' lblcscore.Text =


    End Sub
    End Class
  • kadghar
    Recognized Expert Top Contributor
    • Apr 2007
    • 1302

    #2
    instead of:

    Me.lblRandNum1. Text = CStr(CInt(10 * Rnd() + 1))

    use

    Me.lblRandNum1. Text &= CStr(CInt(10 * Rnd() + 1)) & " "

    this will add them to the label, instead of replacing its content.

    Note: if you're using old versions of VB or VBA it should be like this:

    Me.lblRandNum1. Text = Me.lblRandNum1. Text & " " & CStr(CInt(10 * Rnd() + 1))

    Comment

    Working...