**“计算机评估Do …循环语句中的循环条件,以确定是否应该处理循环指令.在这种情况下,inputales<> String.Empty条件将输入销售变量的最大容量与String.Empty值.如您所知,String.Empty值表示零长度或空的字符串,如果inputsales变量为空,则循环条件计算为True,计算机处理循环指令.*如果另一方面inputales变量不为空,循环条件的计算结果为false,计算机跳过循环指令.
根据代码,我认为它是相反的:…虽然inputales值不为空,但它应该计算为true并处理循环,如果它是空的,它应该计算为false并跳过循环?请看下面.非常感谢你的帮助!
Option Explicit On Option Strict On Imports System.Globalization Public Class SalesForm Private Sub exitButton_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles exitButton.Click Me.Close() End Sub Private Sub calcButton_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles calcButton.Click Const prompt As String = "Enter a sales amount. Click cancel to end." Const title As String = "Sales Entry" Dim inputsales As String Dim sales As Decimal Dim salesCounter As Integer Dim salesaccumulator As Decimal Dim salesAverage As Decimal Dim isconverted As Boolean inputsales = InputBox(prompt,title,"0") **Do While inputsales <> String.Empty isconverted = Decimal.TryParse(inputsales,NumberStyles.Currency,NumberFormatInfo.CurrentInfo,sales) If isconverted = True Then salesCounter = salesCounter + 1 salesaccumulator = salesaccumulator + sales Else MessageBox.Show("Please re-entere the sales amount.","sales Express",MessageBoxButtons.OK,MessageBoxIcon.Information) End If inputsales = InputBox(prompt,"0") Loop** If salesCounter > 0 Then salesAverage = salesaccumulator / Convert.ToDecimal(salesCounter) averageLabel.Text = salesAverage.ToString("C2") Label2.Text = salesCounter.ToString Else averageLabel.Text = "0" End If End Sub End Class
As you know,the String.Empty value represents a zero length,or empty,string. If the
inputsales
variable is not empty,the loop condition evaluates toTrue
,and the computer processes the loop instructions (and then jumps back to the top of the loop and reevaluates the condition). If,on the other hand,theinputsales
variable is empty,the loop condition evaluates toFalse
,and the computer skips over the loop instructions (and continues with the first statement after the loop).
正如@xanatos所说:恭喜你在别人的文字中抓住你的第一个错误.所以问题就是1,我会说这对你的编程生涯很有希望. 原文链接:https://www.f2er.com/vb/255461.html