Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open a file in VB

Status
Not open for further replies.

Mungovan

Programmer
Oct 24, 2002
94
IE
Hi,
I have a standard If statement in one of my subs. I want the application to open a file when one of these conditions of meet. What is this command e.g:

open = c:/myFile ???

Thanks,
D
 
Try this:

OPEN file$ [FOR mode] [ACCESS access] [lock] AS [#]filenumber% [LEN=reclen%]

file$ The name of the file or device. The file name may include a drive and path.

mode One of the following file modes: APPEND,
BINARY, INPUT, OUTPUT, or RANDOM.

access In network environments, specifies whether
the file is opened for READ, WRITE, or READ
WRITE access.

lock Specifies the file locking in network
environments:
SHARED, LOCK READ, LOCK WRITE, LOCK READ
WRITE.

filenumber A number in the range 1 through 255 that
identifies the file while it is open.

reclen For random-access files, the record length
(default is 128 bytes). For sequential
files, the number of characters buffered
(default is 512 bytes).

Example:

n$ = "C:\README.TXT"
OPEN n$ FOR OUTPUT AS #1
PRINT #1, "This is saved to the file."
CLOSE #1

OPEN n$ FOR INPUT AS #1
INPUT #1, a$
MsgBox "Read from file: " & a$
CLOSE #1
 
Thanks,

I use the command
Open "C:\Testing" For Random As #5

but nothing happens, even though the file C:\Testing
does exist at that location. The application doesn't even give an error??


Any ideas??
Thanks
D
 
By opening you mean, showing its contents to the user?

You'll have to shell it, if that's the case...

Greetings,
Rick
 
Yes, I need to show its contents to the user. i.e open a word file.

Any ideas??

Thanks,
D
 
See the VB shell function, the ShellExecute API or the CreateProcess API....

Greetings,
Rick
 
Hi,

Basically, all I need to do is to get VB to open a web-page when a certain condition is true i.e:


If TRUE
Open web site
Else
Send an error message
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top