Vous êtes sur la page 1sur 5

This tutorial will show you how to make a calculator that calculates two

textboxes automatically without any control.

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.

Program to Shutdown - Restart - or Log


Off Computer - Visual Basic .NET
Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013
This tutorial will show you how to create a Shutdown utility in visual basic .net.

The program created will be used to perform operations such as shutting


down the computer, restart it or log off the user

I’m using Visual Studio 2008 but it will work on express even if not studio.

Change the form name to whatever you want.

Set the maximize box and minimize box property to “false”. Change
formborderstyle to FixedSingle.

Add 3 Groupboxes and 3 buttons to the form.


Rename the controls:

GroupBox1 = Shutdown

Groupbox2 = Restart

Groupbox3 = Log Off

Button1 = Click here to Shut Down

Button2= Click here to restart

Button3=Click here to Log Off.


It should look like on the left.

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

Vous aimerez peut-être aussi