CSDN博客

img bruceYing

VB算24点

发表于2002/8/22 9:45:00  622人阅读

VERSION 5.00
Begin VB.Form frmMain
   BorderStyle     =   1  'Fixed Single
   Caption         =   "  24点"
   ClientHeight    =   4020
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   5325
   Icon            =   "Form1.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   4020
   ScaleWidth      =   5325
   StartUpPosition =   3  '窗口缺省
   Begin VB.Timer t
      Interval        =   20000
      Left            =   4440
      Top             =   2310
   End
   Begin VB.CommandButton cmdExit
      Caption         =   "退出"
      Height          =   525
      Left            =   3330
      TabIndex        =   6
      Top             =   3030
      Width           =   975
   End
   Begin VB.CommandButton cmdDo
      Caption         =   "求解"
      Height          =   525
      Left            =   2160
      TabIndex        =   1
      Top             =   3030
      Width           =   975
   End
   Begin VB.CommandButton cmdMake
      Caption         =   "出题"
      Height          =   525
      Left            =   960
      TabIndex        =   0
      Top             =   3030
      Width           =   975
   End
   Begin VB.Label lresult
      AutoSize        =   -1  'True
      BeginProperty Font
         Name            =   "宋体"
         Size            =   15.75
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   315
      Left            =   450
      TabIndex        =   7
      Top             =   1560
      Width           =   165
   End
   Begin VB.Label lNumberD
      AutoSize        =   -1  'True
      Caption         =   "0"
      BeginProperty Font
         Name            =   "宋体"
         Size            =   48
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H0000C000&
      Height          =   960
      Left            =   4200
      TabIndex        =   5
      Top             =   300
      Width           =   480
   End
   Begin VB.Label lNumberB
      AutoSize        =   -1  'True
      Caption         =   "0"
      BeginProperty Font
         Name            =   "宋体"
         Size            =   48
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H0080FF80&
      Height          =   960
      Left            =   1680
      TabIndex        =   4
      Top             =   300
      Width           =   480
   End
   Begin VB.Label lNumberC
      AutoSize        =   -1  'True
      Caption         =   "0"
      BeginProperty Font
         Name            =   "宋体"
         Size            =   48
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H0000FF00&
      Height          =   960
      Left            =   2940
      TabIndex        =   3
      Top             =   300
      Width           =   480
   End
   Begin VB.Label lNumberA
      AutoSize        =   -1  'True
      Caption         =   "0"
      BeginProperty Font
         Name            =   "宋体"
         Size            =   48
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C0FFC0&
      Height          =   960
      Left            =   420
      TabIndex        =   2
      Top             =   300
      Width           =   480
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim NumberA, NumberB, NumberC, NumberD As Single
Dim A, B, C, D As Single
Dim Jieguo As Single
Dim ResultExpression As String
Dim i As Integer
Dim Num As Boolean


Sub Kind(i As Integer)
Select Case i
  Case 1
  A = NumberA: B = NumberB: C = NumberC: D = NumberD
  Case 2
  A = NumberA: B = NumberB: D = NumberC: C = NumberD
  Case 3
  A = NumberA: C = NumberB: B = NumberC: D = NumberD
  Case 4
  A = NumberA: C = NumberB: D = NumberC: B = NumberD
  Case 5
  A = NumberA: D = NumberB: B = NumberC: C = NumberD
  Case 6
  A = NumberA: D = NumberB: C = NumberC: B = NumberD
 
  Case 7
  B = NumberA: A = NumberB: C = NumberC: D = NumberD
  Case 8
  B = NumberA: A = NumberB: D = NumberC: C = NumberD
  Case 9
  B = NumberA: C = NumberB: A = NumberC: D = NumberD
  Case 10
  B = NumberA: C = NumberB: D = NumberC: A = NumberD
  Case 11
  B = NumberA: D = NumberB: A = NumberC: C = NumberD
  Case 12
  B = NumberA: D = NumberB: C = NumberC: A = NumberD
 
  Case 13
  C = NumberA: A = NumberB: B = NumberC: D = NumberD
  Case 14
  C = NumberA: A = NumberB: D = NumberC: B = NumberD
  Case 15
  C = NumberA: B = NumberB: A = NumberC: D = NumberD
  Case 16
  C = NumberA: B = NumberB: D = NumberC: A = NumberD
  Case 17
  C = NumberA: D = NumberB: A = NumberC: B = NumberD
  Case 18
  C = NumberA: D = NumberB: B = NumberC: A = NumberD
 
  Case 19
  D = NumberA: A = NumberB: B = NumberC: C = NumberD
  Case 20
  D = NumberA: A = NumberB: C = NumberC: B = NumberD
  Case 21
  D = NumberA: B = NumberB: A = NumberC: C = NumberD
  Case 22
  D = NumberA: B = NumberB: C = NumberC: A = NumberD
  Case 23
  D = NumberA: C = NumberB: A = NumberC: B = NumberD
  Case 24
  D = NumberA: C = NumberB: B = NumberC: A = NumberD
End Select
 

 
End Sub

Private Sub cmdDo_Click()
For j = 1 To 30
  Select Case j
     Case 1
     For i = 1 To 1
      Call Kind(i)
      Jieguo = A + B + C + D
      If Jieguo = 24 Then
       ResultExpression = A & "+" & B & "+" & C & "+" & D & "=24"
       Num = True
       lresult.Caption = ResultExpression
       Exit For
      End If
     Next i
     Case 2
     For i = 1 To 24
      Call Kind(i)
      Jieguo = A + B + C - D
      If Jieguo = 24 Then
       ResultExpression = A & "+" & B & "+" & C & "-" & D & "=24"
       Num = True
       lresult.Caption = ResultExpression
       Exit For
      End If
     Next i
     Case 3
     For i = 1 To 24
      Call Kind(i)
      Jieguo = A * B + C + D
      If Jieguo = 24 Then
       ResultExpression = A & "*" & B & "+" & C & "+" & D & "=24"
       Num = True
       lresult.Caption = ResultExpression
       Exit For
      End If
     Next i
     Case 4
     For i = 1 To 24
      Call Kind(i)
      Jieguo = A * B + C - D
      If Jieguo = 24 Then
       ResultExpression = A & "*" & B & "+" & C & "-" & D & "=24"
       Num = True
       lresult.Caption = ResultExpression
       Exit For
      End If
     Next i
     Case 5
     For i = 1 To 24
      Call Kind(i)
      Jieguo = A * B * C + D
      If Jieguo = 24 Then
       ResultExpression = A & "*" & B & "*" & C & "+" & D & "=24"
       Num = True
       lresult.Caption = ResultExpression
       Exit For
      End If
     Next i
     Case 6
     For i = 1 To 24
      Call Kind(i)
      Jieguo = A * B * C - D
      If Jieguo = 24 Then
       ResultExpression = A & "*" & B & "*" & C & "-" & D & "=24"
       Num = True
       lresult.Caption = ResultExpression
       Exit For
      End If
     Next i
     Case 7
     For i = 1 To 24
      Call Kind(i)
      Jieguo = A * B * C * D
      If Jieguo = 24 Then
       ResultExpression = A & "*" & B & "*" & C & "*" & D & "=24"
       Num = True
       lresult.Caption = ResultExpression
       Exit For
      End If
     Next i
     Case 8
     For i = 1 To 24
      Call Kind(i)
      Jieguo = A * B + C * D
      If Jieguo = 24 Then
       ResultExpression = A & "*" & B & "+" & C & "*" & D & "=24"
       Num = True
       lresult.Caption = ResultExpression
       Exit For
      End If
     Next i
     Case 9
     For i = 1 To 24
      Call Kind(i)
      Jieguo = A * B - C * D
      If Jieguo = 24 Then
       ResultExpression = A & "*" & B & "-" & C & "*" & D & "=24"
       Num = True
       lresult.Caption = ResultExpression
       Exit For
      End If
     Next i
     Case 10
     For i = 1 To 24
      Call Kind(i)
      Jieguo = A / B + C + D
      If Jieguo = 24 Then
       ResultExpression = A & "/" & B & "+" & C & "+" & D & "=24"
       Num = True
       lresult.Caption = ResultExpression
       Exit For
      End If
     Next i
     Case 11
     For i = 1 To 24
      Call Kind(i)
      Jieguo = A * B / C + D
      If Jieguo = 24 Then
       ResultExpression = A & "*" & B & "/" & C & "+" & D & "=24"
       Num = True
       lresult.Caption = ResultExpression
       Exit For
      End If
     Next i
     Case 12
     For i = 1 To 24
      Call Kind(i)
      Jieguo = A * B / C - D
      If Jieguo = 24 Then
       ResultExpression = A & "*" & B & "/" & C & "-" & D & "=24"
       Num = True
       lresult.Caption = ResultExpression
       Exit For
      End If
     Next i
     Case 13
     For i = 1 To 24
      Call Kind(i)
      Jieguo = A * B * C / D
      If Jieguo = 24 Then
       ResultExpression = A & "*" & B & "*" & C & "/" & D & "=24"
       Num = True
       lresult.Caption = ResultExpression
       Exit For
      End If
     Next i
     Case 14
     For i = 1 To 24
      Call Kind(i)
      Jieguo = A * B / C / D
      If Jieguo = 24 Then
       ResultExpression = A & "*" & B & "/" & C & "/" & D & "=24"
       Num = True
       lresult.Caption = ResultExpression
       Exit For
      End If
     Next i
     Case 15
     For i = 1 To 24
      Call Kind(i)
      Jieguo = (A + B) * C / D
      If Jieguo = 24 Then
       ResultExpression = "(" & A & "+" & B & ")*" & C & "/" & D & "=24"
       Num = True
       lresult.Caption = ResultExpression
       Exit For
      End If
     Next i
     Case 16
     For i = 1 To 24
      Call Kind(i)
      Jieguo = (A + B) * C * D
      If Jieguo = 24 Then
       ResultExpression = "(" & A & "+" & B & ")*" & C & "*" & D & "=24"
       Num = True
       lresult.Caption = ResultExpression
       Exit For
      End If
     Next i
     Case 17
     For i = 1 To 24
      Call Kind(i)
      Jieguo = (A + B) * (C + D)
      If Jieguo = 24 Then
       ResultExpression = "(" & A & "+" & B & ")*(" & C & "+" & D & ")=24"
       Num = True
       lresult.Caption = ResultExpression
       Exit For
      End If
     Next i
     Case 18
     For i = 1 To 24
      Call Kind(i)
      Jieguo = (A + B) * (C - D)
      If Jieguo = 24 Then
       ResultExpression = "(" & A & "+" & B & ")*(" & C & "-" & D & ")=24"
       Num = True
       lresult.Caption = ResultExpression
       Exit For
      End If
     Next i
     Case 19
     For i = 1 To 24
      Call Kind(i)
      Jieguo = (A - B) * (C - D)
      If Jieguo = 24 Then
       ResultExpression = "(" & A & "-" & B & ")*(" & C & "-" & D & ")=24"
       Num = True
       lresult.Caption = ResultExpression
       Exit For
      End If
     Next i
     Case 20
     For i = 1 To 24
      Call Kind(i)
      Jieguo = (A - B) * C / D
      If Jieguo = 24 Then
       ResultExpression = "(" & A & "-" & B & ")*" & C & "/" & D & "=24"
       Num = True
       lresult.Caption = ResultExpression
       Exit For
      End If
     Next i
     Case 21
     For i = 1 To 24
      Call Kind(i)
      Jieguo = (A - B) * C * D
      If Jieguo = 24 Then
       ResultExpression = "(" & A & "-" & B & ")*" & C & "*" & D & "=24"
       Num = True
       lresult.Caption = ResultExpression
       Exit For
      End If
     Next i
     Case 22
     For i = 1 To 24
      Call Kind(i)
      Jieguo = (A + B + C) * D
      If Jieguo = 24 Then
       ResultExpression = "(" & A & "+" & B & "+" & C & ")*" & D & "=24"
       Num = True
       lresult.Caption = ResultExpression
       Exit For
      End If
     Next i
     Case 23
     For i = 1 To 24
      Call Kind(i)
      Jieguo = (A + B + C) / D
      If Jieguo = 24 Then
       ResultExpression = "(" & A & "+" & B & "+" & C & ")/" & D & "=24"
       Num = True
       lresult.Caption = ResultExpression
       Exit For
      End If
     Next i
     Case 24
     For i = 1 To 24
      Call Kind(i)
      Jieguo = (A + B - C) * D
      If Jieguo = 24 Then
       ResultExpression = "(" & A & "+" & B & "-" & C & ")*" & D & "=24"
       Num = True
       lresult.Caption = ResultExpression
       Exit For
      End If
     Next i
     Case 25
     For i = 1 To 24
      Call Kind(i)
      Jieguo = A * (B + C) + D
      If Jieguo = 24 Then
       ResultExpression = A & "*(" & B & "+" & C & ")+" & D & "=24"
       Num = True
       lresult.Caption = ResultExpression
       Exit For
      End If
     Next i
     Case 26
     For i = 1 To 24
      Call Kind(i)
      Jieguo = A * (B - C) + D
      If Jieguo = 24 Then
       ResultExpression = A & "*(" & B & "-" & C & ")+" & D & "=24"
       Num = True
       lresult.Caption = ResultExpression
       Exit For
      End If
     Next i
     Case 27
     For i = 1 To 24
      Call Kind(i)
      Jieguo = A * (B + C) - D
      If Jieguo = 24 Then
       ResultExpression = A & "*(" & B & "+" & C & ")-" & D & "=24"
       Num = True
       lresult.Caption = ResultExpression
       Exit For
      End If
     Next i
     Case 28
     For i = 1 To 24
      Call Kind(i)
      Jieguo = A * (B - C) - D
      If Jieguo = 24 Then
       ResultExpression = A & "*(" & B & "-" & C & ")-" & D & "=24"
       Num = True
       lresult.Caption = ResultExpression
       Exit For
      End If
     Next i
     Case 29
     For i = 1 To 24
      Call Kind(i)
      Jieguo = A + (B + C) / D
      If Jieguo = 24 Then
       ResultExpression = A & "+(" & B & "+" & C & ")/" & D & "=24"
       Num = True
       lresult.Caption = ResultExpression
       Exit For
      End If
     Next i
     Case 30
     ResultExpression = "无解"
    
     Num = True
       lresult.Caption = ResultExpression
       End Select
      
   If Num = True Then Exit For
Next j

End Sub
Private Sub cmdExit_Click()
End
End Sub
Private Sub cmdMake_Click()
Randomize
NumberA = Int(Rnd * 10) + 1
NumberB = Int(Rnd * 10) + 1
NumberC = Int(Rnd * 10) + 1
NumberD = Int(Rnd * 10) + 1
lNumberA.Caption = NumberA
lNumberB.Caption = NumberB
lNumberC.Caption = NumberC
lNumberD.Caption = NumberD
lresult.Caption = "请按求解键!"
cmdDo.Enabled = True
Num = False

End Sub

Private Sub Form_Load()
cmdDo.Enabled = False
t.Enabled = False
lresult.Caption = "请按出题键!"
Num = False

End Sub

0 0

相关博文

我的热门文章

img
取 消
img