第一题:新建一个工程,在窗体上画3个文本框,一个按钮,把按钮(COMMAND1)的Caption属性改为1,text1作为变量框1,text2作为变量框2,text3作为暂存变量框。其他label控件自己添上。。
代码如下:
Private Sub Command1_Click()
Select Case Command1.Caption
Case "1"
Text3.Text = Text1.Text
Command1.Caption = "2"
Case "2"
Text1.Text = Text2.Text
Command1.Caption = "3"
Case "3"
Text2.Text = Text3.Text
End Select
End Sub
Private Sub Form_Load()
Text1.Text = "A"
Text2.Text = "B"
Text3.Text = ""
End Sub
第二题
比较麻烦的
界面你画 6个LABEL ,1个COMMAND,5个TEXT
代码
Dim num As Integer
Private Sub Command1_Click()
Label6.Caption = "您的总分为" & num & "分"
End Sub
Private Sub Form_Load()
Randomize
num = 0
If Int(Rnd(1) + 0.5) = 1 Then
Label1.Caption = Int(10 * Rnd) & " × " & Int(10 * Rnd) & " = "
Else
10 a1 = Int(10 * Rnd)
b1 = Int(10 * Rnd)
If Len((a1 * b1)) = 2 And b1 <> 0 Then
Label1.Caption = a1 * b1 & " ÷ " & b1 & " = "
Else
GoTo 10
End If
End If
If Int(Rnd(1) + 0.5) = 1 Then
Label2.Caption = Int(10 * Rnd) & " × " & Int(10 * Rnd) & " = "
Else
20 a2 = Int(10 * Rnd)
b2 = Int(10 * Rnd)
If Len((a2 * b2)) = 2 And b2 <> 0 Then
Label2.Caption = a2 * b2 & " ÷ " & b2 & " = "
Else
GoTo 20
End If
End If
If Int(Rnd(1) + 0.5) = 1 Then
Label3.Caption = Int(10 * Rnd) & " × " & Int(10 * Rnd) & " = "
Else
30 a3 = Int(10 * Rnd)
b3 = Int(10 * Rnd)
If Len((a3 * b3)) = 2 And b3 <> 0 Then
Label3.Caption = a3 * b3 & " ÷ " & b3 & " = "
Else
GoTo 30
End If
End If
If Int(Rnd(1) + 0.5) = 1 Then
Label4.Caption = Int(10 * Rnd) & " × " & Int(10 * Rnd) & " = "
Else
40 a4 = Int(10 * Rnd)
b4 = Int(10 * Rnd)
If Len((a4 * b4)) = 2 And b4 <> 0 Then
Label4.Caption = a4 * b4 & " ÷ " & b4 & " = "
Else
GoTo 40
End If
End If
If Int(Rnd(1) + 0.5) = 1 Then
Label5.Caption = Int(10 * Rnd) & " × " & Int(10 * Rnd) & " = "
Else
50 a5 = Int(10 * Rnd)
b5 = Int(10 * Rnd)
If Len((a5 * b5)) = 2 And b5 <> 0 Then
Label5.Caption = a5 * b5 & " ÷ " & b5 & " = "
Else
GoTo 50
End If
End If
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If Mid(Label1.Caption, 3, 1) = "×" Then
If Text1.Text = a1 * b1 Then
num = num + 20
End If
Else
If Text1.Text = a1 Then
num = num + 20
End If
End If
Text1.Enabled = False
End If
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If Mid(Label2.Caption, 3, 1) = "×" Then
If Text2.Text = a1 * b1 Then
num = num + 20
End If
Else
If Text2.Text = a1 Then
num = num + 20
End If
End If
Text2.Enabled = False
End If
End Sub
Private Sub Text3_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If Mid(Label3.Caption, 3, 1) = "×" Then
If Text3.Text = a1 * b1 Then
num = num + 20
End If
Else
If Text3.Text = a1 Then
num = num + 20
End If
End If
Text3.Enabled = False
End If
End Sub
Private Sub Text4_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If Mid(Label4.Caption, 3, 1) = "×" Then
If Text4.Text = a1 * b1 Then
num = num + 20
End If
Else
If Text4.Text = a1 Then
num = num + 20
End If
End If
Text4.Enabled = False
End If
End Sub
Private Sub Text5_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If Mid(Label5.Caption, 3, 1) = "×" Then
If Text5.Text = a1 * b1 Then
num = num + 20
End If
Else
If Text5.Text = a1 Then
num = num + 20
End If
End If
Text5.Enabled = False
End If
End Sub
如果需要源程序请与我联系QQ170558808,加时,请注明VB
别的题目懒的回答了,需要的话问我
好好学,这些题把书看懂了,一两个小时就搞定了