<< Chapter < Page Chapter >> Page >

' Kiem tra co chon hay khong?

If L1.ListIndex = -1 Then Exit Sub

' Chep

L2.AddItem L1.List(L1.ListIndex)

' Xoa ben trai

L1.RemoveItem L1.ListIndex

End Sub

Bây giờ hàm xử lý sự kiện của Command1 (Command1_Click) ta sửa lại như sau:

Call Chuyendulieu(Form1.List1, Form1.List2)

Hàm Command2_Click:

Call Chuyendulieu(Form1.List2, Form1.List1)

Lưu dự án và chạy chương trình. Kiểm tra kết quả.

Bài tập 1i -4

TRUYỀN THEO ĐỊA CHỈ VÀ TRUYỀN THEO GIÁ TRỊ

Bước 1: Tham số đưa vào chương trình con được truyền theo một trong 2 cách: theo địa chỉ và theo giá trị. Bây giờ ta tạo dự án mới trong thư mục Basic\Bt2-4 để kiểm tra chúng.

Bước 2: Tạo Form1 như sau:

Hình I.12: Truyền tham số321

Button 1: Name: cmdTTri; Caption: Truyen tri

Button 2: Name: cmdTChieu; Caption: Tham chieu

TextBox: Name: Text1

Label 1: Name: lblTruoc

Label 2: Name: lblTrong

Label 3: Name: lblSau

Bước 3: Thêm 1 Modul vào dự án tên là Modul1, chọn Tools\Add Procedure thêm thủ tục Thamchieu như sau:

Name: Thamchieu

Type: Sub

Scope: Public

Bước 4: Thêm đoạn mã sau trong thủ tục Thamchieu

Public Sub Thamchieu(so As Integer)

so = so + 2

Form1.lblTrong.Caption = Str(so)

End Sub

Bước 5: Chọn Tool\Add Procedure để thêm thủ tục Truyentri như sau:

Name: Truyentri

Type: Sub

Scope: Public

Bước 6: Thêm đoạn mã sau trong thủ tục Truyentri

Public Sub Truyentri(ByVal so As Integer)

so = so + 2

Form1.lblTrong.Caption = Str(so)

End Sub

Bước 7: Sự khác nhau giữa 2 thủ tục trên là từ khóa ByVal trong thủ tục Truyentri. Bây giờ ta thêm thủ tục xử lý biến cố Click của Button cmdTTri. Thêm đoạn mã sau:

Private Sub cmdTTri_Click()

Dim n As Integer

n = Val(Text1.Text)

lblTruoc.Caption = Str(n)

Call Truyentri(n)

lblSau.Caption = Str(n)

End Sub

Bước 9: Thêm hàm xử lý biến cố cmdTChieu_Click cho Button cmdTChieu:

Private Sub cmdTChieu_Click()

Dim n As Integer

n = Val(Text1.Text)

lblTruoc.Caption = Str(n)

Call Thamchieu(n)

lblSau.Caption = Str(n)

End Sub

Bước 10: Lưu dự án, chạy chương trình. Nhập số bất kỳ vào ô TextBox rồi nhấp nút Truyen tri, sau đó nhấp nút Tham chieu. Kiểm tra kết quả. Giải thích.

Bài tập 1ii-5

Tham số tùy chọn

Bước 1: Tạo thư mục tên Basic\Bt1II-5. Tạo dự án mới trong thư mục này.

Bước 2: Tạo Form như sau:

Hình I.13: Lấy thời gian

Trong đó:

Label: Name: lblTg

Button 1: Name: cmdGioPhut

Button 2: Name: cmdGioPhutGiay

Bước 3: Thêm modul mới vào dự án tên Modul1. Chọn Tool\ Add Procedure tạo thủ tục:

Name: Laythoigian

Type: Sub

Scope: Public

Bước 3: Thêm đoạn mã sau vào thủ tục trên:

Public Sub Laythoigian(gio As String, phut As String, Optional giay As String)

' Tham so thu 3 co tu khoa Optional, nghia la ta

' co the goi thu tuc co the co tham so nay hay khong co deu duoc

' Ham IsMissing kiem tra xem tham so nay co hay khong

If IsMissing(giay) Then giay = ""

Dim hientai

hientai = Now

gio = Format$(hientai, "hh")

phut = Format$(hientai, "nn")

giay = Format$(hientai, "ss")

End Sub

Bước 4: Thêm thủ tục xử lý sự kiện cho Button cmdGiophutgiay, trong thủ tục này chèn đoạn mã sau:

Private Sub cmdGiophutgiay_Click()

Dim gioht As String

Dim phutht As String

Dim giayht As String

Call Laythoigian(gioht, phutht, giayht)

Questions & Answers

A golfer on a fairway is 70 m away from the green, which sits below the level of the fairway by 20 m. If the golfer hits the ball at an angle of 40° with an initial speed of 20 m/s, how close to the green does she come?
Aislinn Reply
cm
tijani
what is titration
John Reply
what is physics
Siyaka Reply
A mouse of mass 200 g falls 100 m down a vertical mine shaft and lands at the bottom with a speed of 8.0 m/s. During its fall, how much work is done on the mouse by air resistance
Jude Reply
Can you compute that for me. Ty
Jude
what is the dimension formula of energy?
David Reply
what is viscosity?
David
what is inorganic
emma Reply
what is chemistry
Youesf Reply
what is inorganic
emma
Chemistry is a branch of science that deals with the study of matter,it composition,it structure and the changes it undergoes
Adjei
please, I'm a physics student and I need help in physics
Adjanou
chemistry could also be understood like the sexual attraction/repulsion of the male and female elements. the reaction varies depending on the energy differences of each given gender. + masculine -female.
Pedro
A ball is thrown straight up.it passes a 2.0m high window 7.50 m off the ground on it path up and takes 1.30 s to go past the window.what was the ball initial velocity
Krampah Reply
2. A sled plus passenger with total mass 50 kg is pulled 20 m across the snow (0.20) at constant velocity by a force directed 25° above the horizontal. Calculate (a) the work of the applied force, (b) the work of friction, and (c) the total work.
Sahid Reply
you have been hired as an espert witness in a court case involving an automobile accident. the accident involved car A of mass 1500kg which crashed into stationary car B of mass 1100kg. the driver of car A applied his brakes 15 m before he skidded and crashed into car B. after the collision, car A s
Samuel Reply
can someone explain to me, an ignorant high school student, why the trend of the graph doesn't follow the fact that the higher frequency a sound wave is, the more power it is, hence, making me think the phons output would follow this general trend?
Joseph Reply
Nevermind i just realied that the graph is the phons output for a person with normal hearing and not just the phons output of the sound waves power, I should read the entire thing next time
Joseph
Follow up question, does anyone know where I can find a graph that accuretly depicts the actual relative "power" output of sound over its frequency instead of just humans hearing
Joseph
"Generation of electrical energy from sound energy | IEEE Conference Publication | IEEE Xplore" ***ieeexplore.ieee.org/document/7150687?reload=true
Ryan
what's motion
Maurice Reply
what are the types of wave
Maurice
answer
Magreth
progressive wave
Magreth
hello friend how are you
Muhammad Reply
fine, how about you?
Mohammed
hi
Mujahid
A string is 3.00 m long with a mass of 5.00 g. The string is held taut with a tension of 500.00 N applied to the string. A pulse is sent down the string. How long does it take the pulse to travel the 3.00 m of the string?
yasuo Reply
Who can show me the full solution in this problem?
Reofrir Reply
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