Monday, 6 February 2012

An Interest Calculator Using a TextBox, a ListBox and a ComboBox

The following example uses a TextBox, a ListBox and a ComboBox to build an interest calculator. The principal amount is loaded on form startup in a  textbox. The ListBox is populated with interest values. The ListBox displays the interest amount earned on the different interest percentages on a principal amount. The interest values are selected from a ComboBox.
Dim principal As Integer
Dim interest1 As String
Dim interest2 As String
Dim interest3 As String
Private Sub Combo1_Click()
'List1.AddItem (principal * interest1 / 100)
If (Combo1.ListIndex = 0) Then
List1.AddItem (principal * interest1 / 100)
ElseIf (Combo1.ListIndex = 1) Then
List1.AddItem (principal * interest2 / 100)
Else
List1.AddItem (principal * interest3 / 100)
End If
End Sub
Private Sub Form_Load()
Text1.Text = 2000
principal = Val(Text1.Text)
interest1 = 9.75
interest2 = 10.5
interest3 = 11
Combo1.AddItem (interest1)
Combo1.AddItem (interest2)
Combo1.AddItem (interest3)
End Sub
Private Sub Text1_LostFocus()
principal = Val(Text1.Text)
End Sub

No comments:

Post a Comment