|
-
Jul 7th, 2002, 08:10 PM
#1
Thread Starter
Member
how to open a file in VB?
-
Jul 7th, 2002, 08:12 PM
#2
Frenzied Member
what type of file?? if its a text file to a text box then use:
VB Code:
Open "C:\File.txt" For Input as #1
Text1.Text = Input(LOF(1),1)
Close #1
End With
-
Jul 7th, 2002, 08:12 PM
#3
Frenzied Member
VB Code:
Open "C:\Path\Filename.ext" For Input As #1
VB Code:
Open "C:\Path\Filename.ext" For Output As #1
MicroBasic
Dragon Shadow Trainer
There is no good or evil in the world...only programmers and fools .
-
Jul 7th, 2002, 08:20 PM
#4
Thread Starter
Member
Private Sub help_Click()
Open "d:\223\234.chm" For Output As #1
End Sub
but no any program was opened?
-
Jul 7th, 2002, 08:28 PM
#5
Member
use file system objects
dim FSO as new filesystemobject
dim TS as textstream
Set TS = FSO.OpenTextFile(MyFile, ForReading) or forwriting or forappending
The Programmers Credo -
Protect dumb-ass from himself.
-
Jul 7th, 2002, 08:31 PM
#6
Member
then
ts.write (whatever)
ts.read(length as long)
The Programmers Credo -
Protect dumb-ass from himself.
-
Jul 7th, 2002, 08:33 PM
#7
Need-a-life Member
Use "F1":
Open Statement
Enables input/output (I/O) to a file.
Syntax
Open pathname For mode [Access access] [lock] As [#]filenumber [Len=reclength]
The Open statement syntax has these parts:
Part Description
pathname Required.String expression that specifies a file name — may include directory or folder, and drive.
mode Required.Keyword specifying the file mode: Append, Binary, Input, Output, or Random. If unspecified, the file is opened for Random access.
access Optional. Keyword specifying the operations permitted on the open file: Read, Write, or Read Write.
lock Optional. Keyword specifying the operations restricted on the open file by other processes: Shared, Lock Read, Lock Write, and Lock Read Write.
filenumber Required. A validfile number in the range 1 to 511, inclusive. Use the FreeFile function to obtain the next available file number.
reclength Optional. Number less than or equal to 32,767 (bytes). For files opened for random access, this value is the record length. For sequential files, this value is the number of characters buffered.
Remarks
You must open a file before any I/O operation can be performed on it. Open allocates a buffer for I/O to the file and determines the mode of access to use with the buffer.
If the file specified by pathname doesn't exist, it is created when a file is opened for Append, Binary, Output, or Random modes.
If the file is already opened by another process and the specified type of access is not allowed, the Open operation fails and an error occurs.
The Len clause is ignored if mode is Binary.
Important In Binary, Input, and Random modes, you can open a file using a different file number without first closing the file. In Append and Output modes, you must close a file before opening it with a different file number.
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Jul 7th, 2002, 08:38 PM
#8
Frenzied Member
Originally posted by flyflydream2002
Private Sub help_Click()
Open "d:\223\234.chm" For Output As #1
End Sub
but no any program was opened?
Ah, you mean you want to Execute a file. use the Shell function:
VB Code:
ProcessID = Shell("d:\223\234.chm", vbNormalFocus)
MicroBasic
Dragon Shadow Trainer
There is no good or evil in the world...only programmers and fools .
-
Jul 7th, 2002, 08:40 PM
#9
-
Jul 7th, 2002, 08:47 PM
#10
Member
true, who ever is writing the program would need to add a reference to "microsoft scripting runtime". and if they dont have that, they should just use a pencil and paper.
The Programmers Credo -
Protect dumb-ass from himself.
-
Jul 7th, 2002, 08:51 PM
#11
-
Jul 7th, 2002, 08:52 PM
#12
-
Jul 7th, 2002, 08:54 PM
#13
Member
the pencil and paper part was a joke because vbscripting in so common.
The Programmers Credo -
Protect dumb-ass from himself.
-
Jul 7th, 2002, 08:54 PM
#14
Frenzied Member
Originally posted by Mc Brain
Try to avoid FSO whenever you can!!
Sage advice.
MicroBasic
Dragon Shadow Trainer
There is no good or evil in the world...only programmers and fools .
-
Jul 7th, 2002, 08:56 PM
#15
Member
why do you want to avoid fso?
The Programmers Credo -
Protect dumb-ass from himself.
-
Jul 7th, 2002, 08:57 PM
#16
Need-a-life Member
Let's quote TurtleTips (I'm too lazy right now to write my own words):
I am famed on VBF for constantly trashing the FileSystemObject, or FSO. The FSO facilitates many file I/O functions. Only problem is most of the time, these functions are overly complicated by using the FSO. More importantly, the FSO adds a several hundred kilobyte dependency to your program, something that 56k users will not appreciate.
Whenever possible, use the intrinsic file I/O functions, including Open, Close, Input, Write, Print, EOF, LOF, Kill, etc.
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Jul 7th, 2002, 08:59 PM
#17
Member
yea, i guess i see what youre saying. if you only need the basic functions, no need to over complicate.
The Programmers Credo -
Protect dumb-ass from himself.
-
Jul 7th, 2002, 09:01 PM
#18
Need-a-life Member
Not only that... Open, Close, Input, Write, Print, EOF, LOF, Kill, etc. are intrinsic I/O functions... you won't need any extra file to get your app working (besides VB runtimes, but you won't be able to get rid of them)
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Jul 7th, 2002, 09:07 PM
#19
-
Jul 8th, 2002, 12:02 AM
#20
Thread Starter
Member
visual basic code:-------------------------------------------------------------ProcessID = Shell("d:\223\234.chm", vbNormalFocus)
-------------------------------------------------------------------------------
But it's wrong!
message:invalidable sub or parameter
-
Jul 8th, 2002, 12:04 AM
#21
Need-a-life Member
Originally posted by flyflydream2002
visual basic code:-------------------------------------------------------------ProcessID = Shell("d:\223\234.chm", vbNormalFocus)
-------------------------------------------------------------------------------
But it's wrong!
message:invalidable sub or parameter
Come again...
what???
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Jul 8th, 2002, 12:06 AM
#22
Thread Starter
Member
I only want to open a help file when the people click help on menu.
Can you understand me?
-
Jul 8th, 2002, 12:10 AM
#23
Need-a-life Member
Try:
VB Code:
Private Declare Function ShellExecute Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory _
As String, ByVal nShowCmd As Long) As Long
Private Const SW_SHOWNORMAL = 1
Private Sub Command1_Click()
ShellExecute 0&, vbNullString, _
"d:\223\234.chm", _
vbNullString, "C:\", SW_SHOWNORMAL
End Sub
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Jul 8th, 2002, 12:18 AM
#24
Thread Starter
Member
No.
it's wrong.
message:Don't open the file
-
Jul 8th, 2002, 12:19 AM
#25
-
Jul 8th, 2002, 12:25 AM
#26
Thread Starter
Member
yes. I change that path to the correct path.
the whole message:Don't open the file:mk:@MSITStore:d:\223\234.chm
-
Jul 8th, 2002, 12:28 AM
#27
-
Jul 8th, 2002, 12:32 AM
#28
Thread Starter
Member
No. How dare you say that!
You can't answer my any question.but you can not say that! understand?
-
Jul 8th, 2002, 12:34 AM
#29
Need-a-life Member
-
Jul 8th, 2002, 12:34 AM
#30
-
Jul 8th, 2002, 12:45 AM
#31
Thread Starter
Member
I know. I am not very clever. I also don't write program with VB ago. But I can't accept anyone who abuse me.
even my english is very bad. So I don't know how to say and you can understand me.
-
Jul 8th, 2002, 12:47 AM
#32
-
Jul 8th, 2002, 12:53 AM
#33
New Member
I used
----------------------------------------------------------------------------
Private Declare Function ShellExecute Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory _
As String, ByVal nShowCmd As Long) As Long
Private Const SW_SHOWNORMAL = 1
Private Sub Command1_Click()
ShellExecute 0&, vbNullString, _
"d:\223\234.chm", _
vbNullString, "C:\", SW_SHOWNORMAL
End Sub
---------------------------------------------------------------------------
and got it working. Here's my question now. What if I know the name of the file I want to open, but I don't know its exact path. I want to open a file that is in the same directory as the executable. I know the files name, how do tell it to look in the same directory.
Thanks,
Steve
-
Jul 8th, 2002, 12:55 AM
#34
Thread Starter
Member
I can open that kind of file by double clicking.
It's ordinary file. It's only a help file like .hlp
-
Jul 8th, 2002, 12:55 AM
#35
-
Jul 8th, 2002, 12:56 AM
#36
Need-a-life Member
Originally posted by flyflydream2002
I can open that kind of file by double clicking.
It's ordinary file. It's only a help file like .hlp
I know what kind of file they are... but they can get corrupted anyway.
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Jul 8th, 2002, 12:57 AM
#37
Thread Starter
Member
Yes.I can open it.
Thank u.
-
Jul 8th, 2002, 12:58 AM
#38
Need-a-life Member
Originally posted by flyflydream2002
Yes.I can open it.
Thank u.
Then, re-check the code I gave you. As you can see, Sr2003 got it working.
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Jul 8th, 2002, 12:59 AM
#39
Thread Starter
Member
Thank everyone.
Thank Mc Brain
-
Jul 8th, 2002, 01:08 AM
#40
New Member
app.path
Can you give me a quick example. I am trying to brush off the rust from my VB skills, been digging through quake 3 code, and its a little different 
Thanks,
Steve
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
|