<< Chapter < Page Chapter >> Page >

Input #1

Đọc một chuỗi từ tập tin cho đến khi gặp ký tự xuống dòng. Ký tự xuống dòng này được bỏ qua trong lệnh Input; do đó nếu muốn hiển thị thành nhiều dòng trên TextBox, ta phải thêm vào ký tự xuống dòng cho mỗi dòng ta đọc được từ tập tin sau đó ta mới hiển thị trên TextBox. Hằng số vbCrLf là sự liên kết 2 ký tự xuống dòng và về đầu dòng.

IN VĂN BẢN RA MÁY IN

Bước 8: Nếu máy in được nối vào, máy in phải được kích hoạt. Ta có thể kiểm tra chúng bằng cách in thử vài dòng văn bản trong Word hay trong Notepad.

Bước 9: Đối tượng Printer sẽ chỉ đến máy in mặc định. Trong hàm xử lý sự kiện Command4_Click chèn thêm đoạn mã:

Printer.Print Text1.Text

Câu lệnh này dùng để in nội dung trong TextBox ra máy in. Tuy nhiên nội dung của TextBox chỉ được in khi chương trình chấm dứt. Để in ngay lập tức, ta cần phải thêm dòng sau:

Printer.EndDoc

Chép dữ liệu vào clipboard

Bước 10: Trong nhiều ứng dụng, nhiều khi ta cần sử dụng dữ liệu qua lại với nhau. Chẳng hạn, người dùng có thể sử dụng dữ liệu được hiển thị trên form hiển thị của chương trình chúng ta sang chương trình xử lý văn bản Microsoft Word. Lúc này, một cách hiệu quả nhất là sử dụng đối tượng Clipboard, đối tượng này cho phép đọc và ghi lên Windows Clipboard từ chương trình ứng dụng:

Thêm đoạn mã sau vào hàm sự kiện Command5_Click:

Clipboard.Clear

Clipboard.SetText Text1.Text

Đóng cửa số mã lệnh lại và chạy chương trình ứng dụng. Nhập một đoạn văn bản, sau đó nhấp Command5. Từ Microsoft Word, sử dụng menu Edit\Paste để lấy dữ liệu từ Clipboard hiển thị.

Bài tập 3-2

Thao tác với resource file

Mục tiêu: Giúp làm quen với tập tin resource của VB, nhất là củng cố các thao tác trên tập tin.

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

Bước 2: Tạo giao diện như hình sau:

51234679108

Hình III.2: Tập tin resource

Trong đó:

Item 1: Caption: Thong tin nguoi su dung

BorderStyle: 3-Fixed Dialog

StartUpPosition: 2-Center Screen

Item 2: Label

Name: lblHelp

Index: 0

Item 3: Label

Name: lblHelp

Index: 1

Item 4: Label

Name: lblHelp

Index: 2

Item 5: TextBox

Name: txtHelp

Index: 0

Item 6: TextBox

Name: txtHelp

Index: 1

Item 7: TextBox

Name: txtHelp

Index: 2

Item 8: CommandButton

Name: cmdHelp

Index: 0

Item 9: CommandButton

Name: cmdHelp

Index: 1

Item 10: CommandButton

Name: cmdHelp

Index: 2

Bước 3: Ta nhận thấy các điều khiển có cùng một tên hiển thị (Thong tin). Mục tiêu của ta là sử dụng tập tin resource (tài nguyên) để thay đổi tên hiển thị trên các điều khiển. Để tạo tập tin tài nguyên, ta vào mục ADD-IN\ADD-IN MANAGER trên menu của VB. Trong các mục của ADD-IN MANAGER nhấp đúp vào resource editor và đóng mục ADD-IN MANAGER lại.

Bước 4: Chọn Tools\Resource Editor trên menu. Mở String Table Editor bằng cách nhấp chuột lên biểu tượng abc của Resource Editor. Cửa sổ soạn thảo cho tập tin tài nguyên sẽ mở ra. Ta nhập các hàng như sau:

ID RESOURCE STRING ID RESOURCE STRING
1 Ten 7 So dt
2 Ho 8 So CMND
3 Ma nv 9 T. trang hn
4 Huy bo 10 Huy bo
5 Vo hieu hoa 11 Ve truoc
6 Ke 12 Hoan tat

Bước 5: Lưu tập tin tài nguyên lại.

Bước 6: Mở cửa sổ soạn thảo mã lệnh. Tạo kiểu do người dùng định nghĩa để lưu dữ liệu cần nhập vào. Thêm đoạn mã sau:

Questions & Answers

what is biology
Hajah Reply
the study of living organisms and their interactions with one another and their environments
AI-Robot
what is biology
Victoria Reply
HOW CAN MAN ORGAN FUNCTION
Alfred Reply
the diagram of the digestive system
Assiatu Reply
allimentary cannel
Ogenrwot
How does twins formed
William Reply
They formed in two ways first when one sperm and one egg are splited by mitosis or two sperm and two eggs join together
Oluwatobi
what is genetics
Josephine Reply
Genetics is the study of heredity
Misack
how does twins formed?
Misack
What is manual
Hassan Reply
discuss biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles
Joseph Reply
what is biology
Yousuf Reply
the study of living organisms and their interactions with one another and their environment.
Wine
discuss the biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles in an essay form
Joseph Reply
what is the blood cells
Shaker Reply
list any five characteristics of the blood cells
Shaker
lack electricity and its more savely than electronic microscope because its naturally by using of light
Abdullahi Reply
advantage of electronic microscope is easily and clearly while disadvantage is dangerous because its electronic. advantage of light microscope is savely and naturally by sun while disadvantage is not easily,means its not sharp and not clear
Abdullahi
cell theory state that every organisms composed of one or more cell,cell is the basic unit of life
Abdullahi
is like gone fail us
DENG
cells is the basic structure and functions of all living things
Ramadan
What is classification
ISCONT Reply
is organisms that are similar into groups called tara
Yamosa
in what situation (s) would be the use of a scanning electron microscope be ideal and why?
Kenna Reply
A scanning electron microscope (SEM) is ideal for situations requiring high-resolution imaging of surfaces. It is commonly used in materials science, biology, and geology to examine the topography and composition of samples at a nanoscale level. SEM is particularly useful for studying fine details,
Hilary
cell is the building block of life.
Condoleezza 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