Disk Access
How can I check for the existance of files?
Compatibility:VB3
VB4
VB5
Use this function:
Public Function fileExist(fileName As String) As Boolean
Dim l As Long
On Error Resume Next
l = FileLen(fileName)
fileExist = Not (Err.Number > 0)
On Error GoTo 0
End Function
I'm trying to read a file with EOF's in it. I can't read past the first EOF.
Compatibility:VB3
VB4
VB5
In VB, there are three modes of I/O. Random, Text, and Binary. When you open a file as Text mode, you are telling VB that the file you're reading is a text file. Text files end with a EOF.
So, the answer would be to open the file as binary. Binary files can have EOFs in them with no problem.
Instead of this:
open "myfile.dat" as #1 for input
Do this:
open "myfile.dat" as #1 for binaryNote that you will have to use slightly different functions in binary mode.
How can I load a file into a TextBox or RichTextBox?
Compatibility:VB3
VB4
VB5
Use the following code:
dim sFile as string
'Set sFile equal to your filename
dim i as long
i = freefile()
open sFile for input as #i
txtMain.text = input$(i,LOF(i))
close #1
How can I make all the files in a directory uppercase or lowercase?
Compatibility:VB3
VB4
VB5
Say you want to take a whole bunch of files and make them all named in lowercase(or uppercase).
Launch VB, and copy and paste this code:
Dim s As String, mypath As String
mypath = "d:\mydir\moredir"
s = Dir$(mypath & "*.txt") '*.* works too
Do While s <> ""
Name mypath & s As mypath & LCase$(s)
s = Dir$()
Loop
I have a program that writes to a file. Instead of adding to it, it overwrites it. What's wrong?
Compatibility:VB3
VB4
VB5
When you open a file like this:
Open ... for output
You're telling VB to create a new file or overwrite the only one.
What you want to say is:
open ... for append
That should solve your problem.
Copyright 2000, David J Berube<Form1@aol.com>. All Rights Reserved.