vb 如何计算a+2b+3c+4d+5e的值以及显示计算式?(上述字母的值都已知)用循环的方式
问题描述:
vb 如何计算a+2b+3c+4d+5e的值以及显示计算式?(上述字母的值都已知)
用循环的方式
答
Dim s(1 To 5), z As Integer
Dim sStr, zStr As String
Dim i As Integer
sStr = "abcde"
For i = 1 To 5
s(i) = InputBox("请输入" & Mid(sStr, i, 1) & "的值:")
If i > 1 Then
zStr = zStr & "+" & s(i) & "*" & i
Else
zStr = s(i)
End If
z = z + s(i) * i
Next i
MsgBox "a+2b+3c+4d+5e=" & zStr & "=" & z