My tutorial has the following code description below:
** "The computer evaluates the loop condition in the Do ... Loop status to determine whether the loop instructions should be processed. In this case, the inputels <> String.Empty condition compares the input sales contour variable to the String.Empty value. As you know, the value String.Empty is a zero length or an empty string if the inputales variable is empty, the loop condition evaluates to True, and the computer processes the loop instructions. * If, on the other hand, the inputales variable is not empty, the loop condition evaluates to false and the computer skips cycle instructions.
Based on the code, I think this is the opposite: ... that when inputales is not empty, it should evaluate to true and process the loop, and if it is empty, should it evaluate to false and skip the loop? See below. Thank you for help!
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, title, "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
Wannabe
source share