VB .NET
Slip6
Q.1) Write a Vb.net program to add two TextBoxes, two Labels and one button at runtime. Accept two numbers in textboxes and handle DivideByZeroException. [Marks 20]
Solution
Public Class runtime
Dim text1 As New TextBox
Dim text2 As New TextBox
Dim WithEvents btn As New Button
Private Sub runtime_Load(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
text1.Visible = True
text1.Location = New Point(30, 30)
text1.Size = New
Size(160, 25)
Me.Controls.Add(text1)
text2.Visible = True
text2.Location = New Point(60, 60)
text2.Size = New
Size(160, 25)
Me.Controls.Add(text2)
btn.Visible = True
btn.Location = New
Point(160, 70)
btn.Size = New
Size(160, 30)
btn.Text = "click"
Me.Controls.Add(btn)
End Sub
Private Sub btn_Click(ByVal
sender As Object,
ByVal e As
System.EventArgs) Handles btn.Click
Dim r As Integer
Try
r = CInt(text1.Text)
\ CInt(text2.Text)
MsgBox("result"
& r)
Catch
ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class
Tags:
VB .NET