Write a computer lottery program with VB6.0

zhaozj2021-02-11  150

Write a computer lottery program with VB6.0

In recent years, I often see the use of computers to draw programs. The author has a small program that happened to himself with VB to achieve computer lottery. The principle is as follows: mainly using the RND function in VB. To achieve random search and chaos, it is possible to achieve the purpose of random draw. The syntax structure of the RND function is RND [(Number)], and the optional Number parameter is a SINGLE or any valid numerical expression. The RND function returns a value of less than 1 but greater than or equal to 0. The value of Number determines how the RND generates a random number. In order to generate a random integer within a range, the following formula can be used: int (UpperBound - LowerBound 1) × RND LOWERBOUND) Here, UpperBound is the upper limit of the random number, and LowerBound is the lower limit of the random number. In addition, INI files are used in the program, and the Windows INI file can be interpreted as a Windows initialization file. It is a text file specifically designed to save applications and run environment information. The INI file is a text file that edits through a text editor such as NotePad. The INI file has a specific format. An INI file is composed of several sections, and each segment contains several keywords (key) and corresponding values ​​(Value). Create an application's own INI file, save some of the operating environment information of the application via the INI file, and then read the setting information in the INI file and processed. Once the program's running environment needs to be changed, you can ensure the availability of the program by directly modifying the INI file or indirectly modifying the INI file indirectly in the program.

FIG Runtime: source code and comments are as follows: 'Form source Option Explicit Dim m_strNameArray () As MyName Dim m_bIsStart As Boolean Dim m_nNameIndex As Integer Dim MAX_INDEX As Integer Dim m_nSelectNum As Integer' selected number Dim nScrollStep As Integer Dim nScrollWidth As Integer Dim bScrollState As Boolean Dim nEnableSecond As Integer Dim m_strTitle As String Dim m_strAppTitle As String Dim m_strScrollTitleLeft As String Dim m_strScrollTitleRight As String Private Sub Command_Start_Stop_Click () If m_bIsStart = True Then 'press the stop button m_bIsStart = False Command_Start_Stop.Caption = " start "Label_FlashName.Visible = True Timer_FlashName.Enabled = True Timer_ScrollName.Enabled = False Label_FlashName = m_strNameArray (m_nNameIndex) .strName " hit the jackpot! "m_strNameArray (m_nNameIndex) .bIsSelect = True m_nSelectNum = m_nSelectNum 1 Dim Temp As MyName Temp = M_StrNameArray (MAX_INDEX) m_str name array (max-index) = m_strnameArray (m_nnameindex) m_strnameArray (m_nnameindex) = Temp max_index = max_index - 1 IF MAX_INDEX = 0 Then MsgBox "Thank you very much to use the software" End If Else 'Press the Start button m_bIsStart = True Command_Start_Stop.Caption = "stop" Command_Start_Stop.Enabled = False Timer_ScrollName.Enabled = True Timer_FlashName.Enabled = False Label_FlashName.Caption = " "End If End Sub Private Sub Form_Load () Form_Bouns.ScaleMode = 3 m_nNameIndex = 0 m_bIsStart = False Timer_ScrollName.Enabled = True Timer_ScrollTitle.Enabled = True Label_FlashName.Visible = False Label_ScrollName.Caption =" "nEnableSecond = 0 'define the start seconds REDIMNAMEARRAY '

Getting the name of the text and chaos nscrollstep = 5 'Setting the rolling word steps nscrollwidth = label_conGruation.left' Setting Title Mobile Width BScrollState = false 'Setting the default start scroll direction to left m_nsentnum = 0 'number 0 is selected to initialize the Init' interface initialization End of the program Sub Private Sub Timer_FlashName_Timer () 'winner name flashing If Label_FlashName.Visible = True Then Label_FlashName.Visible = False Else Label_FlashName.Visible = True End If End Sub Private Sub Timer_ScrollName_Timer () 'scroll name appears If m_bIsStart = True Then If m_nNameIndex> = MAX_INDEX Then m_nNameIndex = 0 End If m_nNameIndex = m_nNameIndex 1 If m_strNameArray (m_nNameIndex) .bIsSelect = True Then If m_nNameIndex 0 Then nscrollwidth = nscro llWidth - nScrollStep Else bScrollState = True End If Else 'right roller nScrollStep = -10 Label_Congruation.Caption = m_strScrollTitleRight If nScrollWidth

True Then Command_Start_Stop.Enabled = True nEnableSecond = 0 End If End If End Sub 'dynamic definition array Private Sub ReDimNameArray () Dim nMaxIndex As Integer Dim strMaxIndex As String Dim nIndex As Integer Dim bIsBegin As Boolean bIsBegin = False nIndex = 0 Open App. Path "/name.txt" For Input As # 1 'to read a file Do Until EOF (1) If bIsBegin = False Then Line Input # 1, strMaxIndex nMaxIndex = Val (strMaxIndex) MAX_INDEX = nMaxIndex - 1 ReDim m_strNameArray (0 To nMaxIndex - 1) bisbegin = true else line input # 1, m_strnameArray (nindex) .strname m_strnamerray (nindex) .bisselect = false nindex = NINDEX 1 End if loop 'below is a sequential sequence 10 DIM I AS INTEGER DIM J AS Integer Dim Temp As String Dim nRandomNum As Integer For j = 0 To 10 For i = 0 To nMaxIndex - 1 nRandomNum = ((nMaxIndex - 1) × Rnd) 'using Rnd function Temp = m_strNameArray (i) .strName m_strNameArray (i) .strname = m_strnamerray (nrandomnum) .strname m_strnameArray (nrandomnum) .strname = Temp next i Next J End Sub Private Sub init ( ) 'Read INI file DIM X as long Dim lpfilename Dim Temp as string × 50 lpfilename = app.path "/sortition.ini" x = getPrivateProfileString ("System", "AppTitle", "Summary", Temp, Len (TEMP), LPFILENAME) M_STRAPPTITLE = Trim (Temp) Temp = "" x = getPrivateProfileString ("System", "Title", "Welcome Lottery Procedure", Temp, Len (Temp), LPFileName) m_STRTITE = TRIM (TEMP) Temp = "" x = getPrivateProfileString ("System", "ScrollTitleright", "Congratulations !!!", Temp, Len (Temp), LPFileName) m_strscrolltitleright = Trim (TEMP) x =

转载请注明原文地址:https://www.9cbs.com/read-5491.html

New Post(0)