我的蓄能器...下一个循环是跳过VB中的数字; Visual Studio 2010。 [英] My Accumulator for my For... Next loop is skipping numbers in VB; Visual Studio 2010.

查看:100
本文介绍了我的蓄能器...下一个循环是跳过VB中的数字; Visual Studio 2010。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个For ... Next循环,该循环将允许12个条目或取消按钮。

intEntries仅使用1、3、5、7、9和11.完成此操作后,将计算结果除以13,而不是除以12.。我不确定这是怎么回事,但这显然是有问题的。您能给我的任何帮助,我们将不胜感激!

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


推荐答案

删除行 decEntries + = 1 的for ..循环自动加一!

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

这篇关于我的蓄能器...下一个循环是跳过VB中的数字; Visual Studio 2010。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆