<< Chapter < Page Chapter >> Page >
Mục tiêu: Chương này gồm các bài tập nhằm rèn luyện cho sinh viên các thao tác cần thiết cho phép thiết kế các ứng dụng đơn giản trong môi trường lập trình Visual Basic cũng như một số kỹ năng lập trình cơ bản khi làm việc với Visual Basic.

Học xong chương này, sinh viên phải nắm bắt được các vấn đề sau:

- Sử dụng các điều khiển để thiết kế giao diện trong Visual Basic.

- Vận dụng các cấu trúc lập trình trong Visual Basic để viết mã lệnh.

- Sử dụng một số cấu trúc dữ liệu trong Visual Basic.

Kiến thức có liên quan:

- Giáo trình “Visual Basic”; Chương 1, 2, 3, 4, 5.

Tài liệu tham khảo:

- Visual Basic 6 Certification Exam Guide - Chapter 1, Page 1; Chapter 2, Page 41; Chapter 4, Page 89 - Dan Mezick&Scot Hillier - McGraw-Hill - 1998.

SỬ DỤNG MỘT SỐ ĐIỀU KHIỂN

Bài tập có hướng dẫn

Bài tập 1i-1

THAO TÁC TRÊN LISTBOX

Bước 1: Tạo thư mục Basic\Bt1-1. Tạo một dự án mới kiểu Standard EXE, lưu vào trong thư mục trên.

Bước 2: Thêm 2 List Box và một Button vào form (hình 1). Nhấn đúp lên form để mở ra cửa sổ Code, nhập các đoạn mã sau trong sự kiện Form_Load:

Form1.List1.AddItem “Thing 3”

Form1.List1.AddItem “Thing 2”

Form1.List1.AddItem “Thing 1”

Hình 1.1: Thao tác với List Box

Bước 3: Chạy ứng dụng bằng cách chọn Run/Start. List1 hiển thị 3 phần tử vừa thêm vào ở bước 2. Chấm dứt chương trình bằng cách chọn Run/End trên menu để trở về môi trường soạn thảo.

Bước 4: Nhấp đúp lên Button Command1 để hiển thị sự kiện Click của Command1.

Bước 5: Mục đích của Command1 là chuyển những phần tử được chọn từ List1 sang List2. Thêm đoạn mã sau vào thủ tục sự kiện Click của Command1:

' Kiem tra neu mot phan tu duoc chon

If Form1.List1.ListIndex = -1 Then Exit Sub

' Chep cac phan tu duoc chon tu List1 sang List2

Form1.List2.AddItem Form1.List1.List(Form1.List1.ListIndex)

Bước 6: Chạy ứng dụng. Nhấp phần tử thứ nhất của List1, sau đó nhấp Command1. Điều gì xảy ra? Phần tử được chọn của List1 phải được hiển thị bên List2. Chấm dứt ứng dụng và trở về môi trường soạn thảo.

Bước 7: Tìm trong phần trợ giúp các thuộc tính sau của ListBox:

oListCount

oList

oListIndex

Bước 8: Tìm trong phần trợ giúp các hàm sau của ListBox:

oAddItem

oRemoveItem

oClear

Bước 9: Tìm trợ giúp cho lệnh VB:

Exit Sub

Bước 10: Đoạn mã trong thủ tục Command1_Click thực hiện thao tác chép phần tử từ một ListBox sang một ListBox khác. Bây giờ ta làm ngược lại: loại bỏ phần tử trong List1. Để làm điều này ta nhấp đúp lên Command1 và thêm dòng code sau vào cuối thủ tục:

' Xoa phan tu duoc chon trong List1

Form1.List1.RemoveItem Form1.List1.ListIndex

Bước 11: Chạy chương trình và chọn phần tử thứ nhất trong List1. Điều gì xảy ra?

Bước 12: Nếu không chọn phần tử nào trong List1, nhấp Command1. Điều gì xảy ra? Tại sao?

Bước 13: Ta đã có một button dùng để chuyển các phần tử được lựa chọn từ trái sang phải (List1 sang List2), với button còn lại ta sẽ dùng để chuyển các phần tử được chọn từ phải sang trái (List2 sang List1).

Bước 14: Với Command2 ta sẽ copy đoạn mã từ Command1 với 1 vài thay đổi nhỏ.

Bước 15: Command2 thực hiện các thao tác giống với Command1, nhưng có nhiệm vụ di chuyển phần tử được lựa chọn từ List2 sang List1. Đoạn mã trong Command1 sẽ được sử dụng lại với một vài thay đổi nhỏ. Nhấp đúp lên Command1, chọn các mã lệnh đã thêm vào ở các bước trước. Chọn Edit/Copy trên menu.

Questions & Answers

differentiate between demand and supply giving examples
Lambiv Reply
differentiated between demand and supply using examples
Lambiv
what is labour ?
Lambiv
how will I do?
Venny Reply
how is the graph works?I don't fully understand
Rezat Reply
information
Eliyee
devaluation
Eliyee
t
WARKISA
hi guys good evening to all
Lambiv
multiple choice question
Aster Reply
appreciation
Eliyee
explain perfect market
Lindiwe Reply
In economics, a perfect market refers to a theoretical construct where all participants have perfect information, goods are homogenous, there are no barriers to entry or exit, and prices are determined solely by supply and demand. It's an idealized model used for analysis,
Ezea
What is ceteris paribus?
Shukri Reply
other things being equal
AI-Robot
When MP₁ becomes negative, TP start to decline. Extuples Suppose that the short-run production function of certain cut-flower firm is given by: Q=4KL-0.6K2 - 0.112 • Where is quantity of cut flower produced, I is labour input and K is fixed capital input (K-5). Determine the average product of lab
Kelo
Extuples Suppose that the short-run production function of certain cut-flower firm is given by: Q=4KL-0.6K2 - 0.112 • Where is quantity of cut flower produced, I is labour input and K is fixed capital input (K-5). Determine the average product of labour (APL) and marginal product of labour (MPL)
Kelo
yes,thank you
Shukri
Can I ask you other question?
Shukri
what is monopoly mean?
Habtamu Reply
What is different between quantity demand and demand?
Shukri Reply
Quantity demanded refers to the specific amount of a good or service that consumers are willing and able to purchase at a give price and within a specific time period. Demand, on the other hand, is a broader concept that encompasses the entire relationship between price and quantity demanded
Ezea
ok
Shukri
how do you save a country economic situation when it's falling apart
Lilia Reply
what is the difference between economic growth and development
Fiker Reply
Economic growth as an increase in the production and consumption of goods and services within an economy.but Economic development as a broader concept that encompasses not only economic growth but also social & human well being.
Shukri
production function means
Jabir
What do you think is more important to focus on when considering inequality ?
Abdisa Reply
any question about economics?
Awais Reply
sir...I just want to ask one question... Define the term contract curve? if you are free please help me to find this answer 🙏
Asui
it is a curve that we get after connecting the pareto optimal combinations of two consumers after their mutually beneficial trade offs
Awais
thank you so much 👍 sir
Asui
In economics, the contract curve refers to the set of points in an Edgeworth box diagram where both parties involved in a trade cannot be made better off without making one of them worse off. It represents the Pareto efficient allocations of goods between two individuals or entities, where neither p
Cornelius
In economics, the contract curve refers to the set of points in an Edgeworth box diagram where both parties involved in a trade cannot be made better off without making one of them worse off. It represents the Pareto efficient allocations of goods between two individuals or entities,
Cornelius
Suppose a consumer consuming two commodities X and Y has The following utility function u=X0.4 Y0.6. If the price of the X and Y are 2 and 3 respectively and income Constraint is birr 50. A,Calculate quantities of x and y which maximize utility. B,Calculate value of Lagrange multiplier. C,Calculate quantities of X and Y consumed with a given price. D,alculate optimum level of output .
Feyisa Reply
Answer
Feyisa
c
Jabir
the market for lemon has 10 potential consumers, each having an individual demand curve p=101-10Qi, where p is price in dollar's per cup and Qi is the number of cups demanded per week by the i th consumer.Find the market demand curve using algebra. Draw an individual demand curve and the market dema
Gsbwnw Reply
suppose the production function is given by ( L, K)=L¼K¾.assuming capital is fixed find APL and MPL. consider the following short run production function:Q=6L²-0.4L³ a) find the value of L that maximizes output b)find the value of L that maximizes marginal product
Abdureman
types of unemployment
Yomi Reply
What is the difference between perfect competition and monopolistic competition?
Mohammed
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Giáo trình visual basic. OpenStax CNX. Jul 29, 2009 Download for free at http://cnx.org/content/col10777/1.1
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Giáo trình visual basic' conversation and receive update notifications?

Ask