首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我需要将for循环中的值存储到数组中。

我需要将for循环中的值存储到数组中。
EN

Stack Overflow用户
提问于 2014-04-12 13:15:26
回答 1查看 44关注 0票数 0

基本上,我被要求在三年的第一季度向用户提供与日照总量有关的价值。

我的主表单上有一个按钮,上面写着“开始”。

单击此按钮时,我希望打开一个提示框。此提示符框应提示用户输入9个值,这些值将在三年内分割。E.g

代码语言:javascript
复制
"Please enter the total sunshine for January 2011"
"Please enter the total sunshine for February 2011"
"Please enter the total sunshine for March 2011"

"Please enter the total sunshine for January 2012"
"Please enter the total sunshine for February 2012"
"Please enter the total sunshine for March 2012"

"Please enter the total sunshine for January 2013"
"Please enter the total sunshine for February 2013"
"Please enter the total sunshine for March 2013"

我需要将值存储在单独的数组中。因此,与三年中的每一年相对应的输入值应该包含在它们自己的数组中。

EN

回答 1

Stack Overflow用户

发布于 2014-04-12 14:47:45

下面的代码将为您所需的内容提供解决方案。由于我不知道输入这些值后将如何处理这些值,我建议您:(a)将它们保存到表或其他地方;(b)添加处理非数字值的代码(即重试)。如果我是一名用户,每次运行例程时都要回答9个问题,我就不会很高兴……

代码语言:javascript
复制
Sub Get_Sunshine_Values()
Dim a2011(3) As Double
Dim a2012(3) As Double
Dim a2013(3) As Double

a2011(1) = InputBox("Please enter the total sunshine for January 2011", "Sunshine")
a2011(2) = InputBox("Please enter the total sunshine for February 2011", "Sunshine")
a2011(3) = InputBox("Please enter the total sunshine for March 2011", "Sunshine")

a2012(1) = InputBox("Please enter the total sunshine for January 2012", "Sunshine")
' repeat for Feb & Mar.

a2013(1) = InputBox("Please enter the total sunshine for January 2013", "Sunshine")
' repeat for Feb & Mar.

End Sub
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23030851

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档