• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

VB算24点

发布: 2007-7-01 21:48 | 作者: admin | 来源: | 查看: 126次 | 进入软件测试论坛讨论

领测软件测试网

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


延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网