vb编程题目

2024-11-19 22:53:51
推荐回答(1个)
回答1:

建议楼主 别搞计算机这行
新建个工程把代码复制到窗体 直接运行就可以了
Private WithEvents Text1 As TextBox
Private WithEvents Label1 As Label
Private WithEvents Label2 As Label
Private WithEvents Label3 As Label
Private WithEvents Label4 As Label
Private WithEvents Label5 As Label
Private WithEvents command1 As CommandButton

Private Sub Form_Load()
'动态加载控件
Set Text1 = Controls.Add("VB.TextBox", "text1")
Set Label1 = Controls.Add("VB.Label", "Label1")
Set Label2 = Controls.Add("VB.Label", "Label2")
Set Label3 = Controls.Add("VB.Label", "Label3")
Set Label4 = Controls.Add("VB.Label", "Label4")
Set Label5 = Controls.Add("VB.Label", "Label5")
Set command1 = Controls.Add("VB.CommandButton", "Command1")
Label1.Caption = "1+1=?"
Label2.Caption = "a、1"
Label3.Caption = "b、2"
Label4.Caption = "c、3"
Label5.Caption = "d、4"
command1.Caption = "确定"
Text1.Visible = True
Label1.Visible = True
Label2.Visible = True
Label3.Visible = True
Label4.Visible = True
Label5.Visible = True
command1.Visible = True
Text1.Left = 1000
command1.Left = 3000
Label2.Top = 800: Label2.Left = 0
Label3.Top = 800: Label3.Left = 1300
Label4.Top = 800: Label4.Left = 2800
Label5.Top = 800: Label5.Left = 4000
End Sub

Private Sub Command1_Click()
If Text1.Text = "" Then
MsgBox "请输入答案"
ElseIf Text1.Text = "b" Then
MsgBox "回答正确"
Else
MsgBox "回答错误"
End If
End Sub