how to use formula b=p (1+r)^n, to calculate annual interests for a savings account in visual basic project

This is my code so far>>>>>>>>>>>>>>

Option Explicit On
Option Strict On
Option Infer Off

Public Class MainForm

Private Function FV(ByVal p As Single, n As Integer) As Double

Const annuinterestrate1 As Double = 0.02
Const annuinterestrate2 As Double = 0.03
Const annuinterestrate3 As Double = 0.04

Dim deposit As Double
Dim withdrawals As Double
Dim r As Single

Dim initialbalance As Double
Dim balance As Double

balance = initialbalance

initialbalance = p * (1 + r) ^ n

Dim interest As Double = Convert.ToDouble(balance * annuinterestrate1 / 12)
balance += Convert.ToDouble(interest)

End Function

Private Function b() As Double
Throw New NotImplementedException()
End Function

Private Sub CalcButton_Click(sender As Object, e As EventArgs) Handles CalcButton.Click

End Sub
End Class

To use the formula b = p(1+r)^n, which calculates the annual interest for a savings account in a Visual Basic project, you need to follow these steps:

1. Declare the required variables in the code:
- p: Initial principal (savings account balance)
- r: Annual interest rate (expressed as a fraction)
- n: Number of years

2. Specify the different interest rates and their corresponding values:
- annuinterestrate1: Annual interest rate for the first year
- annuinterestrate2: Annual interest rate for the second year
- annuinterestrate3: Annual interest rate for the third year

3. Calculate the initial balance using the formula b = p(1+r)^n:
- Initialize the variable "initialbalance" to store the calculated value of the initial balance.
- Compute the initial balance using: initialbalance = p * (1 + r) ^ n.

4. Calculate the annual interest and update the account balance:
- Initialize the variable "balance" to store the account balance.
- Compute the interest for each year:
- For example, for annuinterestrate1, calculate the interest using: interest = balance * annuinterestrate1 / 12.
- Update the account balance by adding the interest: balance += interest. Repeat this step for each year.

Here's an updated version of your code to illustrate these steps:

Option Explicit On
Option Strict On
Option Infer Off

Public Class MainForm

Private Function CalculateInterest(ByVal principal As Single, ByVal years As Integer) As Double

Const annuinterestrate1 As Double = 0.02
Const annuinterestrate2 As Double = 0.03
Const annuinterestrate3 As Double = 0.04

Dim r As Double ' Annual interest rate
Dim initialbalance As Double ' Initial balance
Dim balance As Double ' Account balance

balance = initialbalance
r = annuinterestrate1 ' Set the interest rate

' Calculate the initial balance using the formula b = p(1+r)^n
initialbalance = principal * (1 + r) ^ years

Dim interest As Double = balance * annuinterestrate1 / 12 ' Calculate the annual interest
balance += interest ' Update the account balance

' Repeat the interest calculation and balance update for the remaining years
' using the respective interest rates (annuinterestrate2, annuinterestrate3).

' Finally, return the updated account balance as the calculated interest.
Return balance

End Function

Private Sub CalcButton_Click(sender As Object, e As EventArgs) Handles CalcButton.Click
' Retrieve the principal and years from the user inputs (TextBoxes)

Dim principal As Single = Convert.ToSingle(PrincipalTextBox.Text)
Dim years As Integer = Convert.ToInt32(YearsTextBox.Text)

' Call the CalculateInterest function and display the result in an appropriate TextBox or Label

Dim interest As Double = CalculateInterest(principal, years)
ResultTextBox.Text = interest.ToString("C") ' C format for currency representation

End Sub

End Class

Make sure to adjust the names of your TextBoxes or Labels in the code according to your project's UI design. Also, don't forget to handle any potential input validation or error handling as necessary.