<< Chapter < Page Chapter >> Page >

lblTg.Caption = gioht&":"&phutht&":"&giayht

End Sub

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

Private Sub cmdGiophut_Click()

Dim gioht As String

Dim phutht As String

' Khong su dung tham so thu ba

Call Laythoigian(gioht, phutht)

lblTg.Caption = gioht&":"&phutht

End Sub

Bước 6: Lưu dự án lại và chạy chương trình. Kiểm tra kết quả.

Bài tập 1ii-6

Param array

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

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

Hình I.14: Param Array

Trong đó:

ListBox: Name: lstTen

Button: Name: cmdds; Caption: Them vao danh sach

Bước 3: Chèn modul mới vào dự án tên Modul1. Sau đó, chọn Tool\Add Procedure để chèn thủ tục sau:

Name: Diends

Type: Sub

Scope: Public

Bước 3: Chèn đoạn mã sau vào thủ tục Diends

Public Sub Diends(ParamArray Ten() As Variant)

' Su dung ParamArray thi mang phai kieu Variant va

' mang nay la tham so cuoi cung cua thu tuc

Dim hten As Variant

For Each hten In Ten()

Form1.lstTen.AddItem hten

Next

End Sub

Bước 4: ParamArray cho phép không cần xác định số lượng các đối số trong một chương trình con. Bây giờ, thêm hàm xử lý sự kiện cho nút cmdds: cmdds_Click:

Private Sub cmdds_Click()

Call Diends("Huynh Xuan Hiep", "Nguyen Van Linh", "Lam Hoai Bao")

Call Diends

Call Diends("Phan Huy Cuong")

End Sub

Bước 5: Lưu dự án lại và chạy chương trình. Kiểm tra kết quả (hình bên dưới). Lưu ý đến lời gọi thủ tục trong sự kiện cmdds_Click (số lượng đối số khác nhau)

Hình I.15: Kết quả Param Array

Bài tập 1ii-7

XỬ LÝ CHUỖI

12345Bước 1: Tạo dự án mới trong thư mục Basic\Bt2-7 với giao diện như sau:

Hình I.16: Xử lý chuỗi

1: Form: Name: frmMain; MinButton: False; MaxButton: False; Font: VNI-Times.

2: Label: Name: lblTen.

3: TextBox: Name: txtTen.

4: CommandButton: Name: cmdTen; Caption: Tách tên.

5: CommandButton: Name: cmdCKT; Caption: Cắt khoảng trắng.

Bước 2: Tạo một hàm cắt khoảng trắng như sau:

Private Function ATrim(ByVal Name As String) As String

Name = LTrim(RTrim(Name))

Do While InStr(Name, "")<>0

Name = Replace(Name, "", "")

Loop

ATrim = Name

End Function

Bước 3: Trong cửa sổ thiết kế Form; nhấp đúp vào Tách tên, ta xử lý đoạn mã cho sự kiện này:

Private Sub cmdTen_Click()

Dim sName As String, Name As String

sName = ATrim(StrConv(txtTen.Text, vbProperCase))

Dim i As Long

i = InStrRev(sName, "")

Name = Right(sName, Len(sName) - i)

MsgBox Name&": "&Str(Len(Name))

End Sub

Bước 4: Sau đó, trở lại cửa sổ thiết kế, nhấp đúp vào Cắt khoảng trắng, ta xử lý:

Private Sub cmdCKT_Click()

Dim sName As String

sName = ATrim(StrConv(txtTen.Text, vbProperCase))

MsgBox sName, , "Kieu du lieu chuoi"

End Sub

Bước 5: Lưu dự án và chạy chương trình.

Bài tập 1ii-8

Xử lý lỗi

Bước 1: Tạo một dự án mới. Dùng Tools\Add Procedure thêm một thủ tục mới tên GoiThuTuc vào Form1 với nội dung như sau:

Public Sub GoiThuTuc()

Dim bien As Integer

MsgBox "Truoc khi gan tri cho bien"

bien = "Bien nguyen khong nhan gia tri la chuoi"

MsgBox "Sau khi gan tri cho bien: "&"Bien = "&Format(bien)

End Sub

Bước 2: Thủ tục xử lý sự kiện Form_Load có nội dung như sau:

Private Sub Form_Load()

Questions & Answers

I only see partial conversation and what's the question here!
Crow Reply
what about nanotechnology for water purification
RAW Reply
please someone correct me if I'm wrong but I think one can use nanoparticles, specially silver nanoparticles for water treatment.
Damian
what is the stm
Brian Reply
is there industrial application of fullrenes. What is the method to prepare fullrene on large scale.?
Rafiq
industrial application...? mmm I think on the medical side as drug carrier, but you should go deeper on your research, I may be wrong
Damian
How we are making nano material?
LITNING Reply
what is a peer
LITNING Reply
What is meant by 'nano scale'?
LITNING Reply
What is STMs full form?
LITNING
scanning tunneling microscope
Sahil
how nano science is used for hydrophobicity
Santosh
Do u think that Graphene and Fullrene fiber can be used to make Air Plane body structure the lightest and strongest. Rafiq
Rafiq
what is differents between GO and RGO?
Mahi
what is simplest way to understand the applications of nano robots used to detect the cancer affected cell of human body.? How this robot is carried to required site of body cell.? what will be the carrier material and how can be detected that correct delivery of drug is done Rafiq
Rafiq
what is Nano technology ?
Bob Reply
write examples of Nano molecule?
Bob
The nanotechnology is as new science, to scale nanometric
brayan
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Damian
Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
Renato
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
?
Kyle
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
Adin
why?
Adin
what school?
Kyle
biomolecules are e building blocks of every organics and inorganic materials.
Joe
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
research.net
kanaga
sciencedirect big data base
Ernesto
Introduction about quantum dots in nanotechnology
Praveena Reply
what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
Bharti
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
Damian Reply
absolutely yes
Daniel
how to know photocatalytic properties of tio2 nanoparticles...what to do now
Akash Reply
it is a goid question and i want to know the answer as well
Maciej
characteristics of micro business
Abigail
for teaching engĺish at school how nano technology help us
Anassong
How can I make nanorobot?
Lily
how did you get the value of 2000N.What calculations are needed to arrive at it
Smarajit Reply
Privacy Information Security Software Version 1.1a
Good
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!





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