1. Trang chủ
  2. » Luận Văn - Báo Cáo

Introduction to visual studio and visual basic

13 0 0
Tài liệu được quét OCR, nội dung có thể không chính xác
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Introduction to visual studio and visual basic
Tác giả Nguyễn Đức Thịnh
Người hướng dẫn N.V.Binh
Trường học Vietnam National University - Hochiminh City International University
Chuyên ngành Electrical Engineering
Thể loại Lab report
Năm xuất bản 2024
Thành phố Hochiminh City
Định dạng
Số trang 13
Dung lượng 1,42 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

- In “Open and Save File Dialog”: When user click on “Open” button, a dialog will show up and allow user to select a text file * txt to open.. When user click “Save” button, a dialog wil

Trang 1

INTERNATIONAL UNIVERSITY

SCHOOL OF ELECTRICAL ENGINEERING

SCADA LAB EEAC003IU

INTRODUCTION TO VISUAL STUDIO AND

VISUAL BASIC

Submitted by Nguyễn Đức Thịnh - EEACIU21064

Date Submitted: April 7*, 2024

Date Performed: April 1: 2024

Lab Section: 1

Course Instructor: N.V.Binh

Trang 2

Number /| Content Score | Comment

1 Format (max 9%)

- Fonttype Yes No

- Font size Yes No

- Lab title Yes No

- Page number Yes No

- Table of contents Yes No

- Header/Footer Yes No

- List of figures (if exists) | Yes No

- List of tables (if exists) | Yes No

- Lab report structure Yes No

2 English Grammar and Spelling (max 6%)

- Spelling Yes No

3 Data and Result Analysis (max 85%)

Total Score

Signature:

Date:

Trang 3

Table of Contents

List of Figures H List of Tables Il Nomenclature I

1 Theoretical Background 1

2 Experimental Procedure 2 2.1 Task 1: 2 2.2 Task 2 3

3 Experimental Results 5 3.1 Experiment 1 5

4 Discussion of Results 9

[Power Electronics Lab] I [EEACO03IU]

Trang 4

List of Figures

Figure 1: Task 1

Figure 2: Task 2

Figure 3: Result Task 1

Figure 4: Result Task 2

List of Tables

Table 1: Common controls Error! Bookmark not defined

Nomenclature

[Power Electronics Lab] I [EEACOO3IU]

Trang 5

1 Theoretical Background

Labels are used to display text It doesn’t accept input

Label Label3 from the user Often a Label is used to describe

another control

TextBox Textboxes are used to get and display text

Button aes A button allows users to perform some action defined

by the programmer by clicking on it

ComboBox — | ComboBox allows users to select one element from a

list of items

ListBox — : h, ListBox allows users to select one element from a list

tế 3 = of items

Radi B A radio button allows users to choose exactly one of

oButton = : a predefined set of options

Check box indicates a two-way choice or state CheckBox1

CheckBox (true/false) which can be changed by users

TrackBar allows users to select the number by TrackBar ụ dragging the slider

NumericUpDown | 0 =) | NumericUpDown allows users to select the number

P ~ | by enterring the number or pressing Up/Down button TabPaQe! Tabpaoe2 TabControl allows applications to define multiple TabControl pages for the same area of a window Each page

consists of a certain type of controls that will displays when the user selects the corresponding tab

Table 1 Common controls

[Power Electronics Lab] 1 [EEAC0031UJ

Trang 6

2 Experimental Procedure

2.1 Task 1:

Design a following user interface:

- In “Basic Operation”:

Select number from (1) and (8) and the operator from (2) combobox When user click

“Calculation” button, the result will be displayed below in a textbox

- In “Quadratic Equation”:

Input a parameter of the quadratic equation in (6), (7) and (8) textboxes When user click

“Solve”, calculate the answer and show on 2 textboxes below, and only consider when

the equation have real number answers

Solve the equation even when a, b or c equal zero

#2 Labt

Ans

Lab 1 - Student Name - Student ID

Basic Math

Basic Operation:

Add

(1) | subtract

Multiply

caicutat 4)

wer

(5)

Quadratic Equation:

(6)x*2 +

Solve (9)

Answer (real numbers only

(10) ana

2

0 (3):

()s‹ — (8)-s

(11)

- em

Click inside the tab page

yp to select it

[Power Electronics Lab]

Figure 1 Task 1

[EEAC0031UJ

Trang 7

2.2 Task 2

Create a new TabPage next to “Basic Math” tab and name it “Dialog and Message Box”

- In “Color Changing”:

When user change value of color (red, green, blue) by the (2), (3) or (4) trackbars, the

color of the form title (1) will be changed to that color

- In “Open and Save File Dialog”:

When user click on “Open” button, a dialog will show up and allow user to select a text file (* txt) to open If user chose a file and click “OK”, the file will be displayed on the

textbox (7) below

When user click “Save” button, a dialog will show up and allow user to select where to save the text file (*.txt) If user click “Save”, the text from the textbox (7) will save to that file

- In “Message Box”:

User select one type of Message (Notification (8), Warning (9) or Error (10)) User inputs

the title text and message text in (11) and (12) textboxes

When user clicks “Display” button, a message box will show up with the same type and text as it has been set up

[Power Electronics Lab] 3 [EEACO03IU]

Trang 8

Lab 1 - Student Name - Student 1D)

| Basic Math Dialog and Message Box

Open and Save File Dialog: seen) „œ8

(7)

Ẳ Message Box: Title:

(8) Notification Message (11

(9) warning Message — mesaoe:

(10)- Error Message (12)

Figure 2 Task 2

[Power Electronics Lab] 4 [EEACO03IU]

Trang 9

3 Experimental Results

3.1 Experiment 1

Lab1 - Nguyen Duc Thinh - EEACIU21064

Basic Math Dialog and Message Box

Basic Operation:

Subtract a

v

Calculate

Answer:

5.00

Quadratic Equation:

Solve

Answer (real numbers only):

041 and |-241

Figure 3 Result Task 1

Code:

Imports System.Xml

Public Class Forml

Private Sub CalculateButton_Click(sender As Object, e As EventArgs)

Handles CalculateButton.Click

Dim result As Double

If OperatorListBox.SelectedItem IsNot Nothing Then

Select Case OperatorListBox SelectedItem ToString() Case ("Add")

result = FirstNumeric.Value + SecondNumeric Value

[Power Electronics Lab] 5 [EEACO03IU]

Trang 10

Case ("Subtract") result = FirstNumeric.Value -— SecondNumeric Value

Case ("Multiply")

result = FirstNumeric.Value * SecondNumeric Value Case ("Divide")

If SecondNumeric.Value <> 0 Then result = FirstNumeric.Value / SecondNumeric.Value Else

OperationResultTextBox.Text = "Undefined" Return

End If End Select

OperationResultTextBox.Text = result ToString("0.00")

End If

End Sub

Private Sub SolveButton_Click(sender As Object, e As EventArgs)

Handles SolveButton.CLlick

Dim a, b, ¢ As Double

Double TryParse(ATextBox.Text, a)

Double TryParse(BTextBox.Text, b)

Double TryParse(CTextBox.Text, c)

If a <> 0 Then

Dim delta As Double

delta = Math.Sqrt(b * b- 4 * a * c)

If Double IsNaN(delta) Then

X1TextBox.Text = "NaN"

X2TextBox.Text = "NaN"

Return Else

X1TextBox.Text = ((-b - delta) / (2 * a)).ToString("0.00")

X2TextBox.Text = ((-b + delta) / (2 * a)).ToString("0.00")

End If ElseIf b <> 0 Then

X1TextBox Text X2TextBox Text ElseIf c <> 0 Then

(-c / b).ToString("®.90")

X1TextBox.Text = "Null"

X2TextBox.Text = ""

Else

X1TextBox Text "Any Number"

X2TextBox Text End If

End Sub

End Class

[Power Electronics Lab] 6 [EEACO03IU]

Trang 11

3.2 Experiment 2

Lab1 - Nguyen Duc Thinh - EEACIU21064

Basic Math Dialog and Message Box

Color changing:

Open and Save File Dialog :

Open Save

| ~)) task2open.txt - Notepad - oO x abcdefgh File Edit Format View Help

labcdefgh

Ln 1,1 100% Windows (CRLF) UTF-8

© Notification Message -

[Notice

© Warning Message

Message:

5

| You have a message

Error Message lYou have a message

Figure 4 Result Task 2

Code:

Imports System XmL

Imports System IO

Private Sub CoLorChange()

FormTitleLabel.ForeColor = Color FromArgb(RedTrackBar Value,

GreenTrackBar.Value, BlueTrackBar Value)

End Sub

Private Sub RedTrackBar_ValueChanged(sender As Object, e As EventArgs)

Handles RedTrackBar.ValueChanged

ColorChange()

End Sub

[Power Electronics Lab] 7 [EEACO03IU]

Trang 12

Private Sub GreenTrackBar_ValueChanged(sender As Object, e As EventArgs) Handles GreenTrackBar.ValueChanged

ColorChange()

End Sub

Private Sub BlueTrackBar_ValueChanged(sender As Object, e As EventArgs) Handles BlueTrackBar ValueChanged

ColorChange()

End Sub

Private Sub OpenFileButton_Click(sender As Object, e As EventArgs)

Handles OpenFileButton Click

Dim OpenFileDialog = New OpenFileDialog()

OpenFileDialog.Filter = "Text Documents|*.txt|ALL File Types|*.*"

OpenFileDialog.Multiselect = False

If OpenFileDialog.ShowDialog() = DialogResult.OK Then

FileContentTextbox.Text =

File.ReadALlText (OpenFileDialog FileName)

End If

End Sub

Private Sub SaveFileButton_Click(sender As Object, e As EventArgs)

Handles SaveFileButton.Click

Dim SaveFileDialog = New SaveFileDialog()

SaveFileDialog.Filter = "Text Documents|*.txt|ALL File Types|*.*"

SaveFileDialog AddExtension = True

If SaveFileDialog.ShowDialog() = DialogResult.OK Then

File.WriteALLText (SaveFileDialog FileName,

FiLeContentTextbox Text)

End Tf

End Sub

Private Sub DisplayMessageButton_Click(sender As Object, e As EventArgs) Handles DisplayMessageButton Click

If NotificationRadioButton.Checked Then

MsgBox (MessageTextBox.Text, MsgBoxStyle.Information,

TitleTextBox Text)

ElseIf WarningRadioButton.Checked Then

MsgBox (MessageTextBox.Text, MsgBoxStyle.ExcLamation,

TitleTextBox Text)

ElseIf ErrorRadioButton.Checked Then

MsgBox (MessageTextBox.Text, MsgBoxStyle.Critical,

TitleTextBox Text)

End If

End Sub

End Class

[Power Electronics Lab] 8 [EEACO03IU]

Trang 13

4 Discussion of Results

Based on the Designing guide and the Coding guide, | have designed an application that has 2 tabs and archives all the requirements Tab 1 can calculate basic operations and solve quadratic equations Tab 2 can change the color of the name and the ID based on 3 color values red, green, blue; it also can write (Save) or read (open) a text file and send 3 types of messages with manual

title and information

[Power Electronics Lab] 9 [EEACO03IU]

Ngày đăng: 13/02/2025, 16:15

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w