2014-04-12 24 views
0

基本上我需要提示用戶輸入與三年第一季度的陽光總計相關的值。我需要將來自for循環的值存儲到數組中


我有我的主窗體上有一個按鈕,說「開始」。

單擊此按鈕時,我想要一個提示框打開。這個提示框應該提示用戶輸入在三年中分割的9個值。例如

"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" 

我需要將值存儲在單獨的數組中。因此,與三年中的每一年相對應的輸入值都應包含在它們自己的數組中。

+1

您使用的是什麼編程語言? –

+0

我正在使用visual basic – user3526809

+0

對不起,沒有經驗與那一個 –

回答

0

下面的代碼將提供一個解決方案到你想要的。由於我不知道在輸入數值後你將如何處理這些數值,所以我敦促你:(a)將它們保存到一張桌子或其他東西上; (b)添加代碼來處理非數字值(即重試)。如果我是用戶,每次運行例程時我都必須回答9個問題,我不會很高興......

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 
相關問題