打开一个空白的Excel点击“工具”菜单,选择“宏”中“Visual Basic”,在弹出的窗口中双击左边的工程中的“ThisWorkbook”然后弹出的空白窗口中输入如下代码:
Dim iWatermelon As Integer
'西瓜
Dim iBanana As Integer
'香蕉
Dim iSeeds As Integer
'瓜子
Dim iBread As Integer
'面包
Sub Countfruit(theNumber As Integer)
'计算水果
iWatermelon = iWatermelon + theNumber
iBanana = iBanana + 2 * theNumber
End Sub
Sub Countsnacks(theNumber As Integer)
'计算零食
iSeeds = iSeeds + theNumber
iBread = iBread + 3 * theNumber
End Sub
Sub CountSomething(theNumber As Integer)
'计算一堆东西
Countfruit (2 * theNumber)
Countsnacks (3 * theNumber)
iBanana = iBanana + theNumber
MsgBox ("现在有" & iWatermelon & "个西瓜;" & iBanana & "个香蕉;" & iSeeds & "包瓜子;" & iBread & "面包")
End Sub
Sub countit()
'开始计算
CountSomething (12)
End Sub
然后把光标放在代码中的“开始计算”后,然后点击工具栏中的运行按钮即可跳出运算结果。
此问题可以用C#编程解决最好!