Using VB to write lottery program

Source: Internet
Author: User

First, interface design

Create a new Standard EXE project. In the Form1 form, place a timer (Timer1), two text boxes (label1,label2), two command buttons (COMMAND1,COMMAND2), and an array of controls containing 7 elements (LABEL3 (0)-label3 (6)).

Second, property settings

All elements in the Label3 control array take the same setting.

Third, code writing

The implementation principle of this program is: when the user clicks the "Start" button, opens the timer, uses the timer control simultaneously to produce two random numbers sj1, the Sj2,sj1 range is the 1~32,SJ2 scope is 0~49. When the sj1=24, with the SJ2 and the previous generation of winning numbers for comparison, if the same as the previous jackpot, then exit this process; If the winning number is different from the previous, then this random number as the winning number. When 7 winning numbers are generated, close the timer control and stop generating random numbers.

Introduction to the functions used in this program:

(1) Randomize: Initializes the number of seeds for the random number.

(2) INT (): Returns an integer that is rounded after a non-reshaping number.

(3) Rnd: Produces a random number between 0~1 (greater than or equal to 0, but less than 1).

(4) QBColor (): Returns the color corresponding to the parameter (0~15).

(5) Val: Converts a character variable to a numeric variable.

(6) Format: formats an expression.

Here's the complete code for the program:

Dim sy as Integer
1 Click event
Private Sub Command1_Click ()
Clear the contents of the Label3 control array
for i=0 to 6
Labe L3 (i). Caption=″″
Next
timer1.enabled=true′ Open the timer
command1.enabled=false′ make the Start button invalid
sy=-1′ index value initialized to-1
End Sub
2 Click event
Private Sub Command2_Click ()
Unload me′ Uninstall this form
End Sub
1 Timer event
Private Sub timer1_t Imer ()
Dim Sj1,sj2,ys as Integer
randomize′ initialization random number
Sj1=int (rnd*32) +1
Sj2=int (rnd*50)
Label1.Caption =sj1′ set the contents of label 1
Ys=int (rnd*6) +9
Label1.forecolor=qbcolor (ys)
If sj2=24 then′ if sj2 equals
sy=sy+1′ index value plus 1
for A=o to Sy
If sj1=val (Label3 (a). Caption) Then
sy=sy-1
Exit Sub
if
Next
Label3 (SY). Ca Ption=format (Sj1,″00″)
Label3 (SY). Forecolor=qbcolor (YS)
End If
if sy=6 then′ if the index value is equal to 6
timer1.enabled= false′ Shutdown Timer
command1.enabled=true′ Mission order button is valid (you can start the lottery again)
End If
End Sub

Click the "Start" button on the toolbar to start the lottery program. Click the Start button, and the Label1 control will quickly display the numbers between 1~32 in a colorful color and produce a 7-digit winning number in the Label3 control array. Click the Start button again, and the program will automatically clear the contents of the Label3 control array and recreate a 7-digit winning number (unlike the previous one).

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.