Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Showing a sequence of random numbers in VB?

Jason

Awesome Bro

terriblevbgui.PNG

What is SUPPOSED to happen is:

Click the start button.
Textbox is disabled.
Label1 (Will be empty at start) displays a random number between 0-9, single, not decimal.
Wait 1 second.
Label1 will display a new number.
This process loops for about 20 turns because I'm evil...
All of the numbers are added to a string (1+2+3+3+7+7+2+9 = 12337729)
Textbox is enabled.
User has to type the numbers into the textbox, and click confirm.
Contents of textbox are displayed at Label3, and the string from before is shown in Label4.
If Label3 is equal to Label4, Big Label3 (No idea why it's the same) displays "Correct!", otherwise, displays "Wrong!"

Clicking the reset button will disable textbox and clear all labels

Now, since I'm extremely rusty with VB, all I can do from the list, is disable and enable textboxes, erase contents of textboxes/labels, show the contents of one label/textbox in another, and do the if statement to see if the contents of two textboxes/labels are the same or not.

What I'd like, is for someone to help with the looping, random number, and making it wait 1 second, since I have literally no idea how to do either of these, although I've done 2/3 of them before, which was looping and random number.

Sorry if it seems a lot, but I'd appreciate any help you can give me!

Thanks!
 
Ok, I can help you with the random numbers, waiting, and possibly the looping:
Follow the directions. This is not tested, so I dunno if it'll work.
Code:
 

'Put these next 4 lines below your Public Class declaration.

Dim StrBld As New System.Text.StringBuilder() 'StringBuilder.

Dim EquationString As String = String.Empty 'This'll hold our addition equation at the end.

Dim rand As New Random() 'Random Class

Dim Total As Integer = 0I 'The total.

 

'Put these in your Button1 Click Event.

Total = 0I 'Reset the Total

StrBld = New System.Text.StringBuilder() 'Clear the string builder, just in case.

TextBox1.Enabled = False 'disable

 

Label1.Text = rand.Next(0, 10) 'From Zero Inclusive to Ten Exclusive (basically Zero to Nine)

System.Threading.Thread.Sleep(1000I) 'Wait for a second.

Label1.Text = rand.Next(0, 10) 'New number.

 

For i = 0 To 19 'Just Generate 20 numbers like you said.

    Dim CurrentNumber As Integer = rand.Next(0, 10)

    Total += CurrentNumber 'Add it to the Total.

    StrBld.Append(String.Format("{0} + "), CurrentNumber.ToString)

Next

 

TextBox1.Enabled = True 'enable

EquationString = StrBld.ToString.Trim("+"c).Trim(" "c) 'This will remove that extra + and space at the end of the equation.

 
Without opening up VS and trying this for myself, that's the best I can give you for now.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top