Write a visual program to calculate average using runtime text-box
Design window:-
Code:
Dim t1 As TextBox
Dim t2 As TextBox
Dim t3 As TextBox
Dim t4 As TextBox
Dim a As Integer
Dim b As Integer
Dim c As Integer
Private Sub cmdClear_Click()
t1.Text = ""
t2.Text = ""
t3.Text = ""
t4.Text = ""
t1.SetFocus
End Sub
Private Sub cmdDisplay_Click()
a = Val(t1.Text)
b = Val(t2.Text)
c = Val(t3.Text)
t4.Text = (a + b + c) / 3
End Sub
Private Sub cmdExit_Click()
Unload Me
End Sub
Private Sub Form_Activate()
Set t1 = Controls.Add("VB.TextBox", "t1")
t1.Visible = True
t1.Height = 600
t1.Width = 2200
t1.Top = 100
t1.Left = 3200
t1.SetFocus
Set t2 = Controls.Add("VB.TextBox", "t2")
t2.Visible = True
t2.Height = 600
t2.Width = 2200
t2.Top = 800
t2.Left = 3200
Set t3 = Controls.Add("VB.TextBox", "t3")
t3.Visible = True
t3.Height = 600
t3.Width = 2200
t3.Top = 1500
t3.Left = 3200
Set t4 = Controls.Add("VB.TextBox", "t4")
t4.Visible = True
t4.Height = 600
t4.Width = 2200
t4.Top = 2200
t4.Left = 3200
End Sub
=============================================
OUTPUT
Design window:-
Code:
Dim t1 As TextBox
Dim t2 As TextBox
Dim t3 As TextBox
Dim t4 As TextBox
Dim a As Integer
Dim b As Integer
Dim c As Integer
Private Sub cmdClear_Click()
t1.Text = ""
t2.Text = ""
t3.Text = ""
t4.Text = ""
t1.SetFocus
End Sub
Private Sub cmdDisplay_Click()
a = Val(t1.Text)
b = Val(t2.Text)
c = Val(t3.Text)
t4.Text = (a + b + c) / 3
End Sub
Private Sub cmdExit_Click()
Unload Me
End Sub
Private Sub Form_Activate()
Set t1 = Controls.Add("VB.TextBox", "t1")
t1.Visible = True
t1.Height = 600
t1.Width = 2200
t1.Top = 100
t1.Left = 3200
t1.SetFocus
Set t2 = Controls.Add("VB.TextBox", "t2")
t2.Visible = True
t2.Height = 600
t2.Width = 2200
t2.Top = 800
t2.Left = 3200
Set t3 = Controls.Add("VB.TextBox", "t3")
t3.Visible = True
t3.Height = 600
t3.Width = 2200
t3.Top = 1500
t3.Left = 3200
Set t4 = Controls.Add("VB.TextBox", "t4")
t4.Visible = True
t4.Height = 600
t4.Width = 2200
t4.Top = 2200
t4.Left = 3200
End Sub
=============================================
OUTPUT