thank u
Printable View
thank u
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
VB Code:
Open "C:\Path\Filename.ext" For Input As #1
VB Code:
Open "C:\Path\Filename.ext" For Output As #1
Private Sub help_Click()
Open "d:\223\234.chm" For Output As #1
End Sub
but no any program was opened?
use file system objects
dim FSO as new filesystemobject
dim TS as textstream
Set TS = FSO.OpenTextFile(MyFile, ForReading) or forwriting or forappending
ts.write (whatever)
ts.read(length as long)
Use "F1":Quote:
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.
Ah, you mean you want to Execute a file. use the Shell function:Quote:
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?
VB Code:
ProcessID = Shell("d:\223\234.chm", vbNormalFocus)
It's not worth it. If you do do this, then you would have to make sure the end user has VBScript installed (OK...few system doesn't, but just in case...:rolleyes:)Quote:
Originally posted by BinaryAnge
use file system objects
dim FSO as new filesystemobject
dim TS as textstream
Set TS = FSO.OpenTextFile(MyFile, ForReading) or forwriting or forappending
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.
Scripting Runtime is included in VBScript.
Anyways, I (and many other people on the forums) usually prefer the Open statement for its ability to write binary/random files with ease (and give you control, too). It's much better than writing on pencil and paper, and certainly better than messing with the file APIs in VB (I've only used them in C++ programming, never VB).
Try to avoid FSO whenever you can!!
the pencil and paper part was a joke because vbscripting in so common. :)
Sage advice.Quote:
Originally posted by Mc Brain
Try to avoid FSO whenever you can!!
why do you want to avoid fso? :)
Let's quote TurtleTips (I'm too lazy right now to write my own words):Quote:
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.
yea, i guess i see what youre saying. if you only need the basic functions, no need to over complicate.
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)
And if there is something that the intruistic functions doesn't support (finding, for example), you can always use the Windows API. Sure, they require separate Windows DLLs, but it's highly unlikely that the end-user will be running your program without having user32, kernel32, shell32, gdi32, advapi, and those files.
visual basic code:-------------------------------------------------------------ProcessID = Shell("d:\223\234.chm", vbNormalFocus)
-------------------------------------------------------------------------------
But it's wrong!
message:invalidable sub or parameter
Come again...Quote:
Originally posted by flyflydream2002
visual basic code:-------------------------------------------------------------ProcessID = Shell("d:\223\234.chm", vbNormalFocus)
-------------------------------------------------------------------------------
But it's wrong!
message:invalidable sub or parameter
what???
I only want to open a help file when the people click help on menu.
Can you understand me?
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
No.
it's wrong.
message:Don't open the file
It's not wrong... are you sure of the file's path!?
yes. I change that path to the correct path.
the whole message:Don't open the file:mk:@MSITStore:d:\223\234.chm
Stupid question.... can you even open the file by double-clicking over it?
No. How dare you say that!
You can't answer my any question.but you can not say that! understand?
NO... I don't understand. What I also don't understand is why are you treating the way you're to someone who's trying to help you. :(
I have problems of my own... but I'm debugging them on my own. I'm not bothering people on this board.
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.
The chm file could got corrupted... if that's so, there's no code in the world that would open the file. That's why I ask you if you can open it by double-clicking... I was checking that the file is not corrupted and that you have all the components needed installed on your machine to open that kind of files.
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
I can open that kind of file by double clicking.
It's ordinary file. It's only a help file like .hlp
UseVB Code:
App.Path
I know what kind of file they are... but they can get corrupted anyway.Quote:
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
Yes.I can open it.
Thank u.
Then, re-check the code I gave you. As you can see, Sr2003 got it working.Quote:
Originally posted by flyflydream2002
Yes.I can open it.
Thank u.
Thank everyone.
Thank Mc Brain
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
Just App.Path.... this would return the folder of your application.
but there is a problem how to change dynamic path.
Dim pathdd As String
pathdd = App.Path
Const dd As String = "\11.chm"
Dim dd1 As String
dd1 = pathdd & dd
ShellExecute 0&, vbNullString, _
"dd1", _
vbNullString, "c:\", SW_SHOWNORMAL
but it's can't do anything.
VB Code:
Dim pathdd As String pathdd = App.Path Const dd As String = "\11.chm" Dim dd1 As String dd1 = pathdd & dd ShellExecute 0&, vbNullString, _ dd1, _ vbNullString, "c:\", SW_SHOWNORMAL
(no quotes)
yes. you are very clever.
thank u
Thank you
I got it working, thanks! Now to try and remember how to make the program call my Close function when the X in the menu bar is clicked. I can get it to close the way I want when a button is clicked, but I can't remember for the life of me how to have it call a function when the X is clicked. Tommorow I will make a new post. It's soo late.
Steve