<< 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

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
Do somebody tell me a best nano engineering book for beginners?
s. Reply
there is no specific books for beginners but there is book called principle of nanotechnology
NANO
what is fullerene does it is used to make bukky balls
Devang Reply
are you nano engineer ?
s.
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
Tarell
what is the actual application of fullerenes nowadays?
Damian
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
Tarell
what is the Synthesis, properties,and applications of carbon nano chemistry
Abhijith Reply
Mostly, they use nano carbon for electronics and for materials to be strengthened.
Virgil
is Bucky paper clear?
CYNTHIA
carbon nanotubes has various application in fuel cells membrane, current research on cancer drug,and in electronics MEMS and NEMS etc
NANO
so some one know about replacing silicon atom with phosphorous in semiconductors device?
s. Reply
Yeah, it is a pain to say the least. You basically have to heat the substarte up to around 1000 degrees celcius then pass phosphene gas over top of it, which is explosive and toxic by the way, under very low pressure.
Harper
Do you know which machine is used to that process?
s.
how to fabricate graphene ink ?
SUYASH Reply
for screen printed electrodes ?
SUYASH
What is lattice structure?
s. Reply
of graphene you mean?
Ebrahim
or in general
Ebrahim
in general
s.
Graphene has a hexagonal structure
tahir
On having this app for quite a bit time, Haven't realised there's a chat room in it.
Cied
what is biological synthesis of nanoparticles
Sanket Reply
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