7,763
社区成员
发帖
与我相关
我的任务
分享
VERSION 5.00
Object = "{3B7C8863-D78F-101B-B9B5-04021C009402}#1.2#0"; "RICHTX32.OCX"
Begin VB.Form frmDoubleBall
BorderStyle = 1 '單線固定
Caption = "雙色球"
ClientHeight = 3900
ClientLeft = 45
ClientTop = 435
ClientWidth = 4680
LinkTopic = "Form1"
LockControls = -1 'True
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3900
ScaleWidth = 4680
StartUpPosition = 2 '螢幕中央
Begin VB.CommandButton btnInitValue
Caption = "原始值"
BeginProperty Font
Name = "新細明體"
Size = 9
Charset = 136
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 600
TabIndex = 7
Top = 1080
Width = 1095
End
Begin VB.CommandButton btnStart
Caption = "開始"
Height = 495
Left = 1980
TabIndex = 6
Top = 1080
Width = 1095
End
Begin VB.CommandButton btnOK
Caption = "確定"
Height = 495
Left = 3360
TabIndex = 5
Top = 1080
Width = 1095
End
Begin RichTextLib.RichTextBox rtxtResult
Height = 1935
Left = 240
TabIndex = 4
TabStop = 0 'False
Top = 1800
Width = 4215
_ExtentX = 7435
_ExtentY = 3413
_Version = 393217
Enabled = -1 'True
ReadOnly = -1 'True
ScrollBars = 2
TextRTF = $"frmDoubleBall.frx":0000
End
Begin VB.TextBox txtBlue
Height = 285
Left = 600
TabIndex = 2
Top = 720
Width = 3855
End
Begin VB.TextBox txtRed
Height = 285
Left = 600
TabIndex = 0
Top = 360
Width = 3855
End
Begin VB.Timer Timer1
Enabled = 0 'False
Interval = 10
Left = 4080
Top = 1200
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "藍"
BeginProperty Font
Name = "新細明體"
Size = 12
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 240
Left = 240
TabIndex = 3
Top = 720
Width = 255
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "紅"
BeginProperty Font
Name = "新細明體"
Size = 12
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H000000FF&
Height = 240
Left = 240
TabIndex = 1
Top = 360
Width = 255
End
End
Attribute VB_Name = "frmDoubleBall"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim RedArr, BlueArr
Dim nRedArr As Integer, nBlueArr As Integer, nCurRed As Integer, nCurBlue As Integer
Dim nCount As Integer, strResultRed As String, strResultBlue As String
Dim bOK As Boolean, CurRedBall As String, nLine As Integer
Private Sub btnInitValue_Click()
txtRed.Text = "01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33"
txtBlue.Text = "01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16"
End Sub
Private Sub btnOK_Click()
bOK = True
End Sub
Private Sub btnStart_Click()
If Trim(txtRed.Text) = "" Then
MsgBox "請輸入待選紅球"
txtRed.SetFocus
Exit Sub
End If
If Trim(txtBlue.Text) = "" Then
MsgBox "請輸入待選藍球"
txtBlue.SetFocus
Exit Sub
End If
RedArr = Split(Trim(txtRed.Text), " ")
nRedArr = UBound(RedArr)
If nRedArr < 6 Then
MsgBox "最少需要6個紅球數"
txtRed.SetFocus
Exit Sub
End If
BlueArr = Split(Trim(txtBlue.Text), " ")
nBlueArr = UBound(BlueArr)
Timer1.Enabled = True
bOK = False
nCount = 0
strResultRed = " "
Randomize
End Sub
Private Sub Timer1_Timer()
If bOK = False Then
nCurRed = Int(Rnd * (nRedArr + 1))
nCurBlue = Int(Rnd * (nBlueArr + 1))
Else
Do Until nCount >= 6
nCurRed = Int(Rnd * (nRedArr + 1))
CurRedBall = RedArr(nCurRed)
nCurBlue = Int(Rnd * (nBlueArr + 1))
If InStr(strResultRed, " " & CurRedBall & " ") = 0 Then
strResultRed = strResultRed & CurRedBall & " "
nCount = nCount + 1
End If
Loop
If nCount >= 6 Then
nCurBlue = Int(Rnd * (nBlueArr + 1))
strResultBlue = BlueArr(nCurBlue)
End If
rtxtResult.Text = rtxtResult.Text & "紅:" & StrOrder(strResultRed, " ") & " 藍:" & strResultBlue & vbCrLf
nLine = nLine + 1
Timer1.Enabled = False
Dim i As Integer
For i = 0 To nLine - 1
'紅
rtxtResult.SelStart = i * 29
rtxtResult.SelLength = 21
rtxtResult.SelColor = vbRed
DoEvents
'藍
rtxtResult.SelStart = i * 29 + 23
rtxtResult.SelLength = 4
rtxtResult.SelColor = vbBlue
Next
End If
End Sub
Private Sub txtBlue_GotFocus()
txtBlue.SelStart = 0
txtBlue.SelLength = Len(txtBlue.Text)
End Sub
Private Sub txtRed_GotFocus()
txtRed.SelStart = 0
txtRed.SelLength = Len(txtRed.Text)
End Sub
'字符串排序
Private Function StrOrder(Str As String, Separator As String) As String
Dim S
Dim nS As Integer, i As Integer, j As Integer
Dim SS As String
S = Split(Str, Separator)
nS = UBound(S)
ReDim P(nS) As String
For i = nS To 1 Step -1
For j = 0 To i - 1
If S(j) > S(j + 1) Then
SS = S(j)
S(j) = S(j + 1)
S(j + 1) = SS
End If
Next
Next
StrOrder = Join(S, Separator)
End Function
Option Explicit
Private Const MaxValue As Long = 35
Private Const MaxIndex As Long = 5
Private Const V = MaxValue - MaxIndex
'获得组合总数
Private Function Total(ByVal M As Long, ByVal N As Long) As Long
Dim i As Long
Dim Result As Double
Result = 1
For i = N To 1 Step -1
Result = Result * M / i
M = M - 1
Next
Total = Result
End Function
'进位
Private Sub Carry(arr(), Optional Idx = MaxIndex)
Do
arr(Idx) = arr(Idx) + 1
If arr(Idx) > V + Idx Then
Idx = Idx - 1
Else
Exit Do
End If
Loop
Do While Idx < MaxIndex
Idx = Idx + 1
arr(Idx) = arr(Idx - 1) + 1
Loop
End Sub
'RT是RichTextBox
Private Sub Command1_Click()
Dim a(1 To MaxIndex)
Dim s() As String
Dim i As Long
Dim N As Long
Dim t As Double
t = Timer
N = Total(MaxValue, MaxIndex)
ReDim s(1 To N)
RT.Text = ""
For i = 1 To MaxIndex - 1
a(i) = i
Next
a(MaxIndex) = MaxIndex - 1
For i = 1 To N
Carry a
s(i) = Join(a)
Next
RT.Text = Join(s, vbCrLf)
MsgBox Timer - t & vbCrLf & N
End Sub