Hi liquid,
The solution is pretty simple if you think about it. You setup a loop where you first ask the user for an amount up front. If they entered a value, check if it is numeric. If it is, add to our counter and add the amount entered to the total.
Then prompt for the next value and start all over again until they either enter a blank or hit cancel. Then you just see if they entered any amounts via the counter and spit out the results.
Below I have put the basics which will get you started collecting your income accounts. All you have to do is repeat the process for your expense accounts. At the end when it is time to show the profit or loss, you can take the variable
total from this example and subtract the expense total from it to get the profit/loss. Then throw on a dollar sign and you are good to go.
CODE
Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
Dim salescount As Integer = 0
Dim total As Decimal = 0D
Dim salesamount As String
' Ask the user for a sales amount
salesamount = InputBox(" Please enter an amount. Click Cancel to end.", "Sales Amount", "0")
' Loop until they enter a blank or hit cancel
Do While salesamount <> ""
' If value is numeric, add to counter and add sales amount to total
If IsNumeric(salesamount) Then
salescount = salescount + 1
total = total + Convert.ToDecimal(salesamount)
Else
MessageBox.Show("The amount must be numeric. ", " Premium Paper", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
' Get next sales amount from user
salesamount = InputBox(" Please enter a amount. Click Cancel to end.", "Sales Amount", "0")
Loop
' If sales were entered, display the number of accounts and the total.
' Otherwise show that no accounts were entered.
If salescount > 0 Then
Me.xMessageLabel.Text = salescount.ToString()
MessageBox.Show("Number of accounts: " & salescount.ToString() & " and amount total is: " & total.ToString())
Else
Me.xMessageLabel.Text = 0
MessageBox.Show("No sales amount were entered. ", "Premium Paper Company", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
The only other note I have for you is that you need to keep track of your data types. You were attempting to dump a string into an integer value. Remember InputBox returns a string, not an integer.
Enjoy the code!
"At DIC we be account collecting coding ninjas!"