539 544




Visual Basic 6 Black Book:File Handling And File Controls
function GetCookie (name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) == arg) { var end = document.cookie.indexOf (";", j); if (end == -1) end = document.cookie.length; return unescape(document.cookie.substring(j, end)); } i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return null; } var m1=''; var gifstr=GetCookie("UsrType"); if((gifstr!=0 ) && (gifstr!=null)) { m2=gifstr; } document.write(m1+m2+m3);            Keyword Title Author ISBN Publisher Imprint Brief Full  Advanced      Search  Search Tips Please Select ----------- Components Content Mgt Certification Databases Enterprise Mgt Fun/Games Groupware Hardware IBM Redbooks Intranet Dev Middleware Multimedia Networks OS Prod Apps Programming Security UI Web Services Webmaster Y2K ----------- New Titles ----------- Free Archive To access the contents, click the chapter and section titles. Visual Basic 6 Black Book (Publisher: The Coriolis Group) Author(s): Steven Holzner ISBN: 1576102831 Publication Date: 08/01/98 function isIE4() { return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') ); } function bookMarkit() { var url="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0"; parent.location.href=url; //var win = window.open(url,"myitk"); //if(!isIE4()) // win.focus(); } Search this book:  














Previous
Table of Contents
Next




Chapter 17File Handling And File Controls


If you need an immediate solution to:
Using The Common Dialogs File Open And File Save As
Creating A File
Getting A File’s Length
Opening A File
Writing To A Sequential File
Writing To A Random Access File
Writing To A Binary File
Reading From Sequential Files
Reading From Random Access Files
Reading From Binary Files
Accessing Any Record In A Random Access File
Closing A File
Saving Files From Rich Text Boxes
Opening Files In Rich Text Boxes
Saving Files From Picture Boxes
Opening Files In Picture Boxes
Using The Drive List Box Control
Using The Directory List Box Control
Using The File List Box Control
Creating And Deleting Directories
Changing Directories
Copying A File
Moving A File
Deleting A File
When Was A File Created? Last Modified? Last Accessed?
Creating A TextStream
Opening A TextStream
Writing To A TextStream
Reading From A TextStream
Closing A TextStream

In Depth
This chapter focuses on file handling and using the file controls in Visual Basic. Here, we’ll see how to:


•  Use the Common Dialogs File Open and File Save As (you can find more information on this topic in Chapter 11).
•  Create a file
•  Open a file
•  Read from a file
•  Write to a file
•  Close a file
•  Read and write files with rich text boxes
•  Use the file controls like the directory list box and drive list box
•  Determine a file’s creation date, last modified date, and more
•  Move and copy files
•  Use the TextStream object

There are three main ways to access files in Visual Basic: as sequential files, as random access files, and as binary files (you set the way you’ll treat a file when you open it). We’ll get an overview of these types of files before turning to the Immediate Solutions.

Sequential Access Files
Sequential files are like tape cassettes—you read data from them in a sequential manner. If you want data at the end of the file, you have to read all the intervening data first. Sequential files are often organized into text strings in Visual Basic. Here are the Visual Basic statements and functions you use with sequential files (the # symbol refers to an open file, as we’ll see):


•  Open
•  Line Input #
•  Print #
•  Write #
•  Input$
•  Input #
•  Close

In addition, Visual Basic supports TextStream objects to make working with sequential files easier, as we’ll see later in this chapter. Here are the major TextStream methods:


•  Read
•  ReadAll
•  ReadLine
•  Write
•  WriteBlankLines
•  WriteLine
•  Close

When do you use sequential files? If you’ve got a text file full of variable-length strings, you usually treat that file as sequential. You can also use sequential files to store binary-format items like numbers.

Random Access Files
If sequential files are like cassettes, random access files are more like CDs. Random files are organized into records (usually of the same length), and you can read a particular record without having to read all the intervening data—you can move to that record in a file directly, just as you can move to a CD track.

Here are the Visual Basic statements and functions you use with random access files:

•  Type…End Type (to create and format records)
•  Open
•  Put #
•  Len
•  Seek
•  LOC
•  Get #
•  Close
When do you use random access files? If you want to create your own database files, formatted as you want them, you’d organize them into records. In fact, any file that you want to organize into records is best formatted as a random access file.

Binary Files
Binary files are simply unformatted binary data, and Visual Basic does not interpret (such as looking for text strings) or organize the contents (into records) of such files at all. These files are just bytes to Visual Basic, and the statements and functions you usually use with these files include the following:


•  Open
•  Get
•  Put
•  Seek
•  Close

Binary files include EXE files, graphics files, and so on.

The FileSystemObject
Besides the preceding file types, Visual Basic includes the FileSystemObject for easy file manipulation on disk. This object includes a number of methods for copying, moving, and deleting files such as these:


•  GetFile
•  CopyFile
•  DeleteFile
•  MoveFile
•  FileExists
•  CreateFolder
•  CreateTextFile
•  OpenTextFile

In fact, you use the FileSystemObject to create TextStream objects (with methods like CreateTextFile and OpenTextFile). We’ll see more about this topic later in this chapter.
That’s it for the overview of files and file handling. It’s time to turn to the Immediate Solutions.
Immediate Solutions
Using The Common Dialogs File Open And File Save As
The usual way to start working with files is to get a file name from the user using the Common Dialogs File Open or File Save As. We’ve covered these dialogs in depth in Chapter 11, but we’ll provide a quick overview here.

You display the File Open and File Save As dialog boxes with the Common Dialog control’s ShowOpen and ShowSave methods. These methods need no arguments passed to them—to set various options, you set the Common Dialog control’s Flags property (see Chapter 11). You can also set the Filter property so the dialog box displays only certain types of files, such as text files.



Previous
Table of Contents
Next






Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.



Wyszukiwarka

Podobne podstrony:
544 548
II CSK 539 07 1
544 (2)
02 (539)
542 544
544,24,artykul
539,14,artykul
541 544
README (544)

więcej podobnych podstron