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
Now that weve created a TextStream, we can write to it, as well see later in this chapter.
Opening A TextStream
To open a TextStream, you use the FileSystemObjects OpenTextFile method:
FileSystemObject.OpenTextFile( filename[, iomode[, create[, format]]])
Here are what the arguments to OpenTextFile mean:
filenameThe file to open.
iomodeIndicates input/output mode. Can be one of two constants, either ForReading or ForAppending.
createBoolean value that indicates whether a new file can be created if the specified file doesnt exist. The value is True if a new file is created; False if it isnt created. The default is False.
formatOne of three values used to indicate the format of the opened file. If omitted, the file is opened as ASCII.
Heres an example where we open a TextStream object corresponding to a file named file.txt:
Private Sub Command2_Click()
Dim FileSystemObject, TextStream As Object
Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
Set TextStream = FileSystemObject.OpenTextFile("c:\file.txt")
End Sub
After youve opened a TextStream object, you can read from it, as well see later in this chapter.
Writing To A TextStream
To write to a TextStream object, you use one of these methods:
Write( string)
WriteLine([ string])
Heres an example where we create a file named file.txt and write a string, Here is some text! to that file. First, we create a new TextStream:
Private Sub Command1_Click()
Dim FileSystemObject, TextStream As Object
Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
Set TextStream = FileSystemObject.CreateTextFile("c:\file.txt", True)
...
Then we write our line of text to the file and close that file:
Private Sub Command1_Click()
Dim FileSystemObject, TextStream As Object
Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
Set TextStream = FileSystemObject.CreateTextFile("c:\file.txt", True)
TextStream.WriteLine ("Here is some text!")
TextStream.Close
End Sub
Reading From A TextStream
To read from a TextStream object, you use one of these methods; note that the Read method lets you specify how many characters to read:
Read( numbercharacters)
ReadAll
ReadLine
Each of these methods returns the text read. Lets see an example. In this case, well open a file, file.txt, and read one line from it, displaying that line in a text box. First, we create a TextStream object for that file:
Private Sub Command1_Click()
Dim FileSystemObject, TextStream As Object
Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
Set TextStream = FileSystemObject.OpenTextFile("c:\file.txt")
...
Next, we use the ReadLine method to read a line from the file and display it in a text box, Text1, and close the TextStream:
Private Sub Command1_Click()
Dim FileSystemObject, TextStream As Object
Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
Set TextStream = FileSystemObject.OpenTextFile("c:\file.txt")
Text1.Text = TextStream.ReadLine
TextStream.Close
End Sub
Closing A TextStream
When youre finished working with a TextStream object, you close it using the Close method. In the following example, we write to a file, file.txt, using a TextStream object and then close that TextStream (and therefore the file) using Close (this method takes no arguments):
Private Sub Command1_Click()
Dim FileSystemObject, TextStream As Object
Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
Set TextStream = FileSystemObject.CreateTextFile("c:\file.txt", True)
TextStream.WriteLine ("Here is some text!")
TextStream.Close
End Sub
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:
576 579579 5822000 10 Szkoła konstruktorówid!57901 (576)Dz U 1998 Nr 91 poz 576579 Finanse Przedsiebiorstw co powinienem wiedziec zaoczni579 (2)fryzury; ;wlosy;dlugie,artykul,579574 576ONKYO KODY DO PILOTA 506,576,606,5100codesWarunki techniczne Dz U 07 86 579więcej podobnych podstron