English 中文(简体)
我的编纂者 接下来的路程是VB的跳板;2010年演播室。
原标题:My Accumulator for my For... Next loop is skipping numbers in VB; Visual Studio 2010.

I am trying to write a For... Next loop that will allow for 12 entries, or the cancel button.
Somehow intEntries is only using 1, 3, 5, 7, 9, and 11. After that is completed the calculation is being divided by 13, and not 12. I m not sure what it is I ve got wrong, but it s apparently something. Any Assistance you can give me is greatly appreciated!

 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
最佳回答

remove the line decEntries += 1 the for .. loop increase by one automatically!

问题回答

页: 1

然而,你也在 lo体中人工加油:

decEntries += 1 




相关问题
Is Shared ReadOnly lazyloaded?

I was wondering when I write Shared ReadOnly Variable As DataType = New DataType() Or alternatively Shared ReadOnly Variable As New DataType() Is it lazy loaded or as the instance initializes? ...

Entertaining a baby with VB.NET

I would like to write a little application in VB.NET that will detect a baby s cry. How would I get started with such an application?

Choose Enter Rather than Pressing Ok button

I have many fields in the page and the last field is a dropdown with list of values. When I select an item in a dropdown and press Enter, it doesn t do the "Ok". Instead I have to manually click on Ok ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

Set Select command in code

On button Click I want to Set the Select command of a Gridview. I do this and then databind the grid but it doesn t work. What am i doing wrong? protected void bttnView_Click(object sender, ...

Hover tooltip on specific words in rich text box?

I m trying to create something like a tooltip suddenly hoovering over the mouse pointer when specific words in the richt text box is hovered over. How can this be done?

热门标签