Académique Documents
Professionnel Documents
Culture Documents
Add three textboxes to the form. Add them in this order: put the first one on
the left side, the second on the middle and the third one the right like the
following picture:
Add two labels to the form and change their text property to + and = :
Double click on the first textbox "the one on the left" and adjust the code to the
following code
?
1 Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArg
_
2 Handles TextBox1.TextChanged
3 TextBox3.Text = Val(TextBox1.Text) + Val(TextBox2.Text)
4 End Sub
Double click on the second textbox "the middle one" and add the following
code:
?
1 Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArg
_
2 Handles TextBox2.TextChanged
3 TextBox3.Text = Val(TextBox1.Text) + Val(TextBox2.Text)
4 End Sub
Run the program and the third textbox should show the total of the first
textbox and the second one as soon you enter numbers in them.
I’m using Visual Studio 2008 but it will work on express even if not studio.
Set the maximize box and minimize box property to “false”. Change
formborderstyle to FixedSingle.
GroupBox1 = Shutdown
Groupbox2 = Restart
Now add the code for “Click here to shut down” button click event:
?
1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Hand
Button1.Click
2 Shell("shutdown -s")
3 End Sub
Now add the code for “Click here to Restart” button click event.
?
1 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Hand
Button2.Click
2 Shell("shutdown -r")
3 End Sub
Now add the code for “Click here to logoff” click event
?
1 Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Hand
Button3.Click
2 Shell("shutdown -l")
3 End Sub
NOTE: If you debug and click on shutdown, it will shutdown, causing you to
lose your work if unsaved.
Find the area of a triangle using VB Program Code: Public Class Form1 Private Sub Button1_Click(ByVal
sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click TextBox2.Text = 3.14 *
TextBox1.Text End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click TextBox5.Text = TextBox3.Text * TextBox4.Text End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button3.Click Dim a As Integer = TextBox6.Text Dim b As Integer = TextBox7.Text Dim c As Integer =
TextBox8.Text Dim s As Double = (a + b + c) / 2 Dim findarea As Double = Math.Sqrt(s * (s - a) * (s - b) * (s
- c)) TextBox9.Text = findarea End Sub End Class