VB程序实验题,求具体操作方法
答案:1 悬赏:0 手机版
解决时间 2021-02-05 18:52
- 提问者网友:蓝莓格格巫
- 2021-02-04 21:39
VB程序实验题,求具体操作方法
最佳答案
- 五星知识达人网友:玩家
- 2021-02-04 22:03
Private Sub Command1_Click()
Dim s As String
s = InputBox("输入圆的半径")
Call mycalc(s)
End Sub
Private Sub mycalc(s As String)
If IsNumeric(s) Then
Dim PI As Double
PI = 4 * Atn(1)
Dim R As Integer
R = CInt(s)
Dim mystr As String
mystr = "圆面积 = " & PI * (R ^ 2) & vbCrLf & vbCrLf
mystr = mystr & "圆周长 = " & PI * R * 2 & vbCrLf & vbCrLf
mystr = mystr & "球体积 = " & PI * (R ^ 3) * 4 / 3
MsgBox mystr
Else
s = InputBox("输入圆的半径")
Call mycalc(s)
End If
End Sub
'第一题结束
'第二题
Private Function getNum(num As Integer, i As Integer)
Select Case i
Case 1 '取个位
getNum = CStr(num Mod 10)
Case 2 '取拾位
getNum = CStr(Int((num Mod 100) / 10))
Case 3 '取佰位
getNum = CStr(Int(num / 100))
End Select
End Function
Private Sub Command2_Click()
Randomize
'随机数
Dim n As Integer
n = int(Rnd * 900 + 100)
'逆序数字
Dim b As String
b = getNum(n, 1) & getNum(n, 2) & getNum(n, 3)
MsgBox "原数字: " & n & vbCrLf & vbCrLf & "翻转数字: " & b
End Sub
Dim s As String
s = InputBox("输入圆的半径")
Call mycalc(s)
End Sub
Private Sub mycalc(s As String)
If IsNumeric(s) Then
Dim PI As Double
PI = 4 * Atn(1)
Dim R As Integer
R = CInt(s)
Dim mystr As String
mystr = "圆面积 = " & PI * (R ^ 2) & vbCrLf & vbCrLf
mystr = mystr & "圆周长 = " & PI * R * 2 & vbCrLf & vbCrLf
mystr = mystr & "球体积 = " & PI * (R ^ 3) * 4 / 3
MsgBox mystr
Else
s = InputBox("输入圆的半径")
Call mycalc(s)
End If
End Sub
'第一题结束
'第二题
Private Function getNum(num As Integer, i As Integer)
Select Case i
Case 1 '取个位
getNum = CStr(num Mod 10)
Case 2 '取拾位
getNum = CStr(Int((num Mod 100) / 10))
Case 3 '取佰位
getNum = CStr(Int(num / 100))
End Select
End Function
Private Sub Command2_Click()
Randomize
'随机数
Dim n As Integer
n = int(Rnd * 900 + 100)
'逆序数字
Dim b As String
b = getNum(n, 1) & getNum(n, 2) & getNum(n, 3)
MsgBox "原数字: " & n & vbCrLf & vbCrLf & "翻转数字: " & b
End Sub
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯