2012-04-17 7 views
0

For ... Nextループを作成しようとしています。これにより、12個のエントリまたはキャンセルボタンが可能になります。
何とかintEntriesは1、3、5、7、9、11のみを使用しています。それが完了すると、計算は13で除算され、12ではなくなります。それは明らかに何かです。あなたが私に与えることができる援助は非常に高く評価されています!My Accumulator for For For ...次のループは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

は自動的に1 ..ループの増加のためのラインdecEntries += 1を削除します!

+0

ありがとう!私のメモに入る! –

3

あなたはNextに到達するたびにインクリメントするために、次に、ループカウンタとしてdecEntriesを有します。

しかし、あなたはまた、ループの途中で「手動」にインクリメントされています

decEntries += 1 
+0

ありがとうございました!私のメモに入る! –

関連する問題