|
-
May 10th, 2001, 04:35 PM
#1
A few questions about text files.
1.) When displaying text from a text file in a text box, is there a way to display it all just how it is, without knowing if there are any commas or line breaks? I have been using the "Open file$ for Input as" method, but If I don't know how many lines there are, or if there are commas, then I have a high chance of getting the past end of input error.
2.) If there is a folder full of text files, is there any way to open a random one without knowing the name of the file?
Thanks in advance
-
May 10th, 2001, 05:09 PM
#2
Re: A few questions about text files.
1) How are you getting past the end of file? Aren't you using the While Not EOF(filenum) syntax?
2) If you use the FileSystemObject, the Folder object has a Files collection - pass it a random number between 1 and the Folder.Files.Count value to open a random file.
have fun,
john
John Pirkey
MCSD
http://www.ShallowWaterSystems.com
http://www.stlvbug.org
John Pirkey
MCSD (VB6)
http://www.stlvbug.org
-
May 10th, 2001, 06:46 PM
#3
Re: A few questions about text files.
1)
Open file$ For Input As #x
Do Until EOF(x)
'Your reading in code here.
Loop
Close #x
Note: Might consider using Line Input #x instead of just Input #x depending on the situation.
2) Place a FileList control on your page. Make it invisible. Change the FileList.Path to whatever the path is. Select a random number from 0 to the .ListCount-1 {RandomFile = int(rnd*(FileList.ListCount-1))}. Your random file name is FileList.List(RandomFile).
-
May 10th, 2001, 07:41 PM
#4
Re: A few questions about text files.
refer http://vblib.virtualave.net
1.) ReadFileText in vbFileIO which read a file into string array and return the no. of line for the file.
2) GetAllFileName in vbFileIO return all filename in a folder and return the no of files in that folder, then you can just use the VB function Randomize & Rnd
HTH
-
May 10th, 2001, 07:43 PM
#5
Re: A few questions about text files.
The following routine willread a text file into a text box leaving all commas, line feeds, Carriage returns, etc intact.
' Read a file into a TEXT box using binary read
' this reduces the exposure of VB editing double quote marks and
' commas out of the text
private Sub Command1_Click()
Dim a
a = "C:\to DO LIST\1.txt"
Open a for binary as #1
Text1.Text = input(FileLen(a), #1)
Close
End Sub
John G
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|