New to VB - NewFile Dialog / SaveFile Dialog help needed.
-
I'll try it again, but last time I tried that it threw an error at the '=' and said it expected an end of statement.As for what version I am using I am not 100% sure, its the built in editor to Microsoft Office 2003. I'll try this in the morning and pop back on here if i still can't get it working. Thanks a bunch for the response!
--Its not broken if it never worked.
Adam.m.Nelson wrote:
I'll try it again, but last time I tried that it threw an error at the '=' and said it expected an end of statement.As for what version I am using I am not 100% sure, its the built in editor to Microsoft Office 2003.
AFAIK, Office 2003 uses VBA for the scripting - it probably doesn't recognise StreamWriter.
-
You're welcome. If that doesn't work, you could also try,
Dim sW As New IO.StreamWriter(pathToFile)
orDim sW As IO.StreamWriter sW = New IO.StreamWriter(pathToFile)
I hope this helps; I haven't used the programming tools included with Office for a couple of years.modified on Tuesday, April 1, 2008 8:47 PM
Hey, I tried what you posted there and got the following error. --Compile error: --Expected end of statement It happened at the first bracket of this line.
sW = New IO.StreamWriter(pathToFile)
If this were C# I would assume I hadn't included the right system file, but i can't seem to declare a system file, ie:using System.IO
Do you know if that is the case with VB, and if so do you know the syntax for including it?--Its not broken if it never worked.
-
Adam.m.Nelson wrote:
I'll try it again, but last time I tried that it threw an error at the '=' and said it expected an end of statement.As for what version I am using I am not 100% sure, its the built in editor to Microsoft Office 2003.
AFAIK, Office 2003 uses VBA for the scripting - it probably doesn't recognise StreamWriter.
Oh, I didn't know that, thanks!. Do you know of any way to write to a file while 'scripting'?
--Its not broken if it never worked.
-
Oh, I didn't know that, thanks!. Do you know of any way to write to a file while 'scripting'?
--Its not broken if it never worked.
You will need to use the "Basic" methods for file handling. For example:
FileHandle = FreeFile()
Open [FilePath] for Output as FileHandle
Print #FileHandle,"This is a test string"
Close FileHandleHTH [Edit]Had to change since < was intepreted differently[/Edit]
-
You will need to use the "Basic" methods for file handling. For example:
FileHandle = FreeFile()
Open [FilePath] for Output as FileHandle
Print #FileHandle,"This is a test string"
Close FileHandleHTH [Edit]Had to change since < was intepreted differently[/Edit]
That did it! thank you very much
--Its not broken if it never worked.
-
That did it! thank you very much
--Its not broken if it never worked.
Adam.m.Nelson wrote:
That did it! thank you very much
You are welcome. :)
-
Adam.m.Nelson wrote:
That did it! thank you very much
You are welcome. :)
Do you know if it is possible to bring up the 'Save As' window to allow the user to select the save location and file name? I got it working allowing the user to enter the location and file name in a seperate cell, but it would be handy to bring up the dialog they are use to seeing any other time they save a windows file.
--Its not broken if it never worked.
-
Do you know if it is possible to bring up the 'Save As' window to allow the user to select the save location and file name? I got it working allowing the user to enter the location and file name in a seperate cell, but it would be handy to bring up the dialog they are use to seeing any other time they save a windows file.
--Its not broken if it never worked.
This dialog is implemented in the CommonDialog Windows control. You can add reference to the ComDlg32.OCX object in your script and use the methods in this object to Open / Save files. This will bring up the familiar Windows file dialog. HTH
-
This dialog is implemented in the CommonDialog Windows control. You can add reference to the ComDlg32.OCX object in your script and use the methods in this object to Open / Save files. This will bring up the familiar Windows file dialog. HTH
Beautiful, I will try that tonight. If its not too much to ask, I have another quick question: This way of doing it leaves an extra cariage return at the end of the file, i tried writing a \b to the file once it is all done, but it literally writes a \b in the file.
Print #FileHandle, "\b"
Print #FileHandle, '\b'
isn't a command as the ' starts a comment. Is there a way to kill that last cariage return?--Its not broken if it never worked.
-
Beautiful, I will try that tonight. If its not too much to ask, I have another quick question: This way of doing it leaves an extra cariage return at the end of the file, i tried writing a \b to the file once it is all done, but it literally writes a \b in the file.
Print #FileHandle, "\b"
Print #FileHandle, '\b'
isn't a command as the ' starts a comment. Is there a way to kill that last cariage return?--Its not broken if it never worked.
The Print statements appends a CR+LF to the text... I don't know of a way you could suppress this.
-
The Print statements appends a CR+LF to the text... I don't know of a way you could suppress this.
hmm, ok, thanks anyways!! I'll play around with it and if I figure something out I will post it here.
--Its not broken if it never worked.
-
Beautiful, I will try that tonight. If its not too much to ask, I have another quick question: This way of doing it leaves an extra cariage return at the end of the file, i tried writing a \b to the file once it is all done, but it literally writes a \b in the file.
Print #FileHandle, "\b"
Print #FileHandle, '\b'
isn't a command as the ' starts a comment. Is there a way to kill that last cariage return?--Its not broken if it never worked.
Put a semi-colon on the end of the
Print
statement.Print #FileHandle, "something...";
This will avoid adding a CRLF to the end of the line it just printed to the file.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
Put a semi-colon on the end of the
Print
statement.Print #FileHandle, "something...";
This will avoid adding a CRLF to the end of the line it just printed to the file.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008Hey hey that did it!, however because i am writing to the file inside of a loop there are no line breaks now. Is there a command I can put at the beginning of the string being written to the file to tell it to create a new line?
--Its not broken if it never worked.
-
Put a semi-colon on the end of the
Print
statement.Print #FileHandle, "something...";
This will avoid adding a CRLF to the end of the line it just printed to the file.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008Actually, never mind, i re-worked the loop to work around it. Thanks a bunch everyone!! ;)
--Its not broken if it never worked.