Experiment code for 5000 times of dice throwing (VB)

Source: Internet
Author: User

Someone once asked me what I thought. During the lecture last night, I wrote this code. Which one thinks it is wrong? Thank you for your correction.

The code is written in accordance with the vs2010 specification.

 

Suppose you start by pressing the start1 button.

Suppose there are six labels for output. (Counting result)

 

Private sub start1_click ()

Dim sz1 as integer 'defines the integer variable sz1 used to store dice results

Dim a %, B %, C %, d %, E %, F % 'defines six Integer Variables A, B, C, D, E, F for statistical results

A = 0

B = 0

C = 0

D = 0

E = 0

F = 0

 

For I = 1 to 5000 'loops 5000 times

Sz1 = int (6-1 + 1) * RND + 1) 'generates a random number from 1 to 6.

Select case sz1

Case 1' if the result is 1, the variable A counts plus 1

A = a + 1

Case 2' if the result is 2, add 2 to the variable B count

B = B + 1

Case 3' if the result is 3, the variable c count plus 3

C = C + 1

Case 4' if the result is 4, the variable d count plus 4

D = d + 1

Case 5' if the result is 5, the variable e count is increased by 5

E = e + 1

Case 6' if the result is 6, the variable f count plus 6

F = f + 1

End Select

Next I

'Use the following statement to output the result to six tags:

Label1.Text = "roll out" & a & "times"

Label2.Text = "throwing two points" & B & "times"

Label3.Text = "three points" & c & "times"

Label4.text = "four points" & D & "times"

Label5.text = "5" & E & "times"

Label6.text = "" & F & "times"

End sub

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.