2012-04-17 64 views
0

我想寫一個For ... Next循環,它將允許12個條目或取消按鈕。
不知何故intEntries只使用1,3,5,7,9和11.在完成之後,計算被除以13,而不是12.我不確定它是什麼,我錯了,但它顯然是某種東西。任何援助,你可以給我非常感謝!My Accumulator for my For ... Next循環在VB中跳過數字; Visual Studio 2010.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 

     'initialize accumulator 
     Dim decEntries As Decimal 
     ' For loop to ask for input. 
     For decEntries = 1 To 12 Or strMonthlyAvg = " " 
      strMonthlyAvg = InputBox("Please Enter the Average for Month # " & decEntries & ":") 
      decEntries += 1 
      lstTemps.Items.Add(strMonthlyAvg) 
      decMontlyAvg = Convert.ToDecimal(strMonthlyAvg) 
      ' This will add the montly average to the total Average Temperature for 
      ' calculations 
      decTotalTemp += decMontlyAvg 

     Next 
     ' Calculation to provide the average temp for all entered values 
     decAnnualAvg = decTotalTemp/decEntries 
     ' convert annual average to string 
     strAnnualAvg = Convert.ToString(decAnnualAvg) 
     ' Display the results for the user 
     lblResults.Text = "The average annual temperature " & vbCrLf & 
          "based on your entries is: " & strAnnualAvg & "." 


    End Sub 

回答

2

刪除行decEntries += 1中由一個自動循環..增加!

+0

謝謝!去我的筆記! – 2012-04-17 15:00:49

3

decEntries作爲for-next循環的計​​數器,達到Next每次遞增。

但是,您也可在循環的中間增加它的手動「:

decEntries += 1 
+0

非常感謝!去我的筆記! – 2012-04-17 15:01:01