Share practical no 12 vb.net,

minhhaophamnhu

New member
#vb.net, #Practical, #12, #tutorial ## Thực tế 12: vb.net

**Giới thiệu**

Trong hướng dẫn này, chúng tôi sẽ tìm hiểu cách sử dụng vb.net để tạo một máy tính đơn giản.Chúng tôi sẽ đề cập đến các chủ đề sau:

* Tạo một dự án mới
* Thêm điều khiển vào biểu mẫu
* Viết mã để thực hiện tính toán
* Chạy ứng dụng

** Tạo một dự án mới **

Để tạo một dự án mới, hãy mở Visual Studio và chọn tệp **> mới> Dự án **.Trong hộp thoại ** New Project **, chọn ** Visual Basic> Windows Forms Ứng dụng ** và nhấp vào ** OK **.

Điều này sẽ tạo ra một dự án mới có tên ** Dự án của tôi **.Dự án sẽ chứa một biểu mẫu duy nhất gọi là ** Form1 **.

** Thêm điều khiển vào biểu mẫu **

Để thêm các điều khiển vào biểu mẫu, nhấp đúp vào trình thiết kế ** Form1 **.Điều này sẽ mở cửa sổ ** Thuộc tính **.Trong cửa sổ ** Thuộc tính **, nhấp vào tab Hộp công cụ ** **.

Hộp công cụ ** ** chứa danh sách tất cả các điều khiển mà bạn có thể thêm vào một biểu mẫu.Để thêm điều khiển vào biểu mẫu, hãy kéo nó từ hộp công cụ ** ** vào biểu mẫu.

Chúng tôi sẽ thêm các điều khiển sau vào biểu mẫu:

*A ** Nhãn ** Điều khiển để hiển thị giá trị đầu vào
*A ** Hộp văn bản ** Điều khiển để nhập giá trị đầu vào
*Nút ** ** Điều khiển để thực hiện tính toán
*A ** Nhãn ** Điều khiển để hiển thị giá trị đầu ra

** Viết mã để thực hiện tính toán **

Để ghi mã để thực hiện các tính toán, nhấp đúp vào điều khiển nút ** **.Điều này sẽ mở bộ chỉnh sửa mã ** **.

Trong Trình chỉnh sửa mã ** **, thêm mã sau:

`` `
Nút phụ riêng1_click (người gửi dưới dạng đối tượng, e là EventArgs) Nút tay cầm1.Click

Đầu vào mờ như double = textbox1.text
Đầu ra mờ như gấp đôi

Nếu radiobutton1.Checked thì
đầu ra = đầu vào * 2
Otherif radiobutton2.ccked sau đó
đầu ra = đầu vào - 1
Otherif radiobutton3.ccked sau đó
đầu ra = đầu vào / 2
Khác
đầu ra = đầu vào + 1
Kết thúc nếu

Label2.Text = output.ToString ()

Kết thúc phụ
`` `

Mã này sẽ nhận được giá trị đầu vào từ điều khiển ** TextBox1 **, thực hiện tính toán dựa trên nút radio đã chọn và hiển thị giá trị đầu ra trong điều khiển ** Label2 **.

** Chạy ứng dụng **

Để chạy ứng dụng, nhấn ** F5 **.Điều này sẽ biên dịch và chạy ứng dụng.

Ứng dụng sẽ hiển thị một máy tính đơn giản với ba nút radio và hai nhãn.Bạn có thể nhập một số vào điều khiển ** TextBox1 **, chọn nút radio và nhấp vào điều khiển nút **1 ** để thực hiện tính toán.

**Phần kết luận**

Trong hướng dẫn này, chúng tôi đã học cách sử dụng vb.net để tạo một máy tính đơn giản.Chúng tôi đề cập đến các chủ đề sau:

* Tạo một dự án mới
* Thêm điều khiển vào biểu mẫu
* Viết mã để thực hiện tính toán
* Chạy ứng dụng

Tôi hy vọng bạn tìm thấy hướng dẫn này hữu ích.Xin vui lòng để lại bất kỳ ý kiến hoặc câu hỏi dưới đây.

## hashtags

* #vb.net
* #thực tế
* #12
* #tutorial
* #Visual Studio
=======================================
#vb.net, #Practical, #12, #tutorial ## Practical 12: VB.NET

**Introduction**

In this tutorial, we will learn how to use VB.NET to create a simple calculator. We will cover the following topics:

* Creating a new project
* Adding controls to the form
* Writing code to perform calculations
* Running the application

**Creating a new project**

To create a new project, open Visual Studio and select **File > New > Project**. In the **New Project** dialog box, select **Visual Basic > Windows Forms Application** and click **OK**.

This will create a new project called **My Project**. The project will contain a single form called **Form1**.

**Adding controls to the form**

To add controls to the form, double-click on the **Form1** designer. This will open the **Properties** window. In the **Properties** window, click on the **Toolbox** tab.

The **Toolbox** contains a list of all the controls that you can add to a form. To add a control to the form, drag it from the **Toolbox** onto the form.

We will add the following controls to the form:

* A **Label** control to display the input value
* A **TextBox** control to enter the input value
* A **Button** control to perform the calculation
* A **Label** control to display the output value

**Writing code to perform calculations**

To write code to perform calculations, double-click on the **Button** control. This will open the **Code Editor**.

In the **Code Editor**, add the following code:

```
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

Dim input As Double = TextBox1.Text
Dim output As Double

If RadioButton1.Checked Then
output = input * 2
ElseIf RadioButton2.Checked Then
output = input - 1
ElseIf RadioButton3.Checked Then
output = input / 2
Else
output = input + 1
End If

Label2.Text = output.ToString()

End Sub
```

This code will get the input value from the **TextBox1** control, perform the calculation based on the selected radio button, and display the output value in the **Label2** control.

**Running the application**

To run the application, press **F5**. This will compile and run the application.

The application will display a simple calculator with three radio buttons and two labels. You can enter a number in the **TextBox1** control, select a radio button, and click the **Button1** control to perform the calculation.

**Conclusion**

In this tutorial, we learned how to use VB.NET to create a simple calculator. We covered the following topics:

* Creating a new project
* Adding controls to the form
* Writing code to perform calculations
* Running the application

I hope you found this tutorial helpful. Please feel free to leave any comments or questions below.

## Hashtags

* #vb.net
* #Practical
* #12
* #tutorial
* #VisualStudio
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top