Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

Posting calculator results to a message Box, newbie VB question

$
0
0
I'm working on creating a calculator that computes compound interest and I'm having some trouble with the final output.
The calculator works but the final output in given in a long list of month by month message box display.
I would like to either have it display in a list box or just trim the output down to the final result.



Public Class Form1

Inherits System.Windows.Forms.Form
Private Sub btncalc_Click(sender As Object, e As EventArgs) Handles btncal.Click
Dim prin As Decimal
Dim rate As Decimal
Dim months As Integer


'converts strings to integer
If Decimal.TryParse(txtPrincipal.Text, prin) And Decimal.TryParse(txtRate.Text, rate) And Integer.TryParse(txtMonths.Text, months) Then
rate /= 100 'convert APR to percentage
rate /= 12 'convert yearly rate to monthly rate
Dim msg As String = ""

For x As Integer = 1 To months
'add month + balance information to output message
msg &= String.Format("Month: {0}, Balance: {1}{2}", x, Math.Round(prin, 2), Environment.NewLine)
'add interest to balance
prin *= (1 + rate)
Next

'displays result
MsgBox(msg)

End If

End Sub
End Class

Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>