VB编程语言基础知识点总结
用VB实现微信消息的发送!
【汇总】VB编程综合整理
一键找回系统登录密码,就是这么Easy!
如何实现多台计算机之间的网络通信?
VB四则运算题目
程序实现分析:
1、使用VB中的随机函数公式去随机生成10道四则运算题目,而且运算符也是随机产生;
2、用户输入计算的答案后,点击核对可以显示出每道题的对错以及所得分数;
3、本程序主要用到了循环结构、选择结构、数组、控件数组等VB核心知识。
程序实现代码:
Option Explicit
Dim a(1 To 10, 1 To 3) As Integer
Dim s(1 To 10) As String * 1
Private Sub Command1_Click() '随机生成题目
Dim i As Integer
For i = 1 To 10
Dim score As Integer
If a(i, 3) = Val(T(i - 1).Text) Then
L(i - 1).ForeColor = vbGreen
L(i - 1).Caption = "对"
score = score + 1
Else
L(i - 1).ForeColor = vbBlue
L(i - 1).Caption = "错"
End If
Next
MsgBox "您本次得分为" & score & "分"
End Sub
Private Sub Command3_Click() '答案验证及评分'
Dim i As Integer
Dim T As Integer
Dim M As Single
Randomize
For i = 1 To 10
a(i, 1) = Int(Rnd * (90 + 10))
a(i, 2) = Int(Rnd * (90 + 1))
Next
For i = 1 To 10
T = Int(Rnd * 4 + 1)
If T = 1 Then
s(i) = "+"
ElseIf T = 2 Then
s(i) = "-"
ElseIf T = 3 Then
s(i) = "*"
Else
s(i) = "/"
End If
Next
For i = 1 To 10
If s(i) = "+" Then
a(i, 3) = a(i, 1) + a(i, 2)
ElseIf s(i) = "-" Then
If a(i, 1) T = a(i, 1): a(i, 1) = a(i, 2): a(i, 2) = T
a(i, 3) = a(i, 1) - a(i, 2)
Else
a(i, 3) = a(i, 1) - a(i, 2)
End If
ElseIf s(i) = "*" Then
a(i, 3) = a(i, 1) * a(i, 2)
ElseIf s(i) = "/" Then
a(i, 3) = a(i, 1) * a(i, 2)
T = a(i, 1): a(i, 1) = a(i, 3): a(i, 3) = T
End If
Next
For i = 1 To 10
L1.AddItem a(i, 1) & s(i) & a(i, 2) & "="
Next
End Sub
Private Sub Command2_Click() '退出程序
End
End Sub
。
程序运行图
Tips:
如果你有VB学习上的问题,可添加老师微信号:vbyjk521,验证消息填写“VB",添加后会耐心为你讲解问题。
长按上图,关注跟我学VB公众平台