Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. New to VB - NewFile Dialog / SaveFile Dialog help needed.

New to VB - NewFile Dialog / SaveFile Dialog help needed.

Scheduled Pinned Locked Moved Visual Basic
helpcsharphardwaretutorialquestion
18 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Mitch F

    I'm not sure what version of Visual Basic Microsoft Office comes with, but in .Net you declare the streamwriter inside of your method (Sub, Function, etc). Dim sW As IO.StreamWriter = New IO.StreamWriter(pathtToFile) sW.Write(Data) sW.Close() sW.Dispose() I hope this helps.

    A Offline
    A Offline
    Adam m Nelson
    wrote on last edited by
    #3

    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.

    M C 2 Replies Last reply
    0
    • A Adam m Nelson

      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.

      M Offline
      M Offline
      Mitch F
      wrote on last edited by
      #4

      You're welcome. If that doesn't work, you could also try, Dim sW As New IO.StreamWriter(pathToFile) or Dim 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

      A 1 Reply Last reply
      0
      • A Adam m Nelson

        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.

        C Offline
        C Offline
        ChandraRam
        wrote on last edited by
        #5

        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.

        A 1 Reply Last reply
        0
        • M Mitch F

          You're welcome. If that doesn't work, you could also try, Dim sW As New IO.StreamWriter(pathToFile) or Dim 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

          A Offline
          A Offline
          Adam m Nelson
          wrote on last edited by
          #6

          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.

          1 Reply Last reply
          0
          • C ChandraRam

            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.

            A Offline
            A Offline
            Adam m Nelson
            wrote on last edited by
            #7

            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.

            C 1 Reply Last reply
            0
            • A Adam m Nelson

              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.

              C Offline
              C Offline
              ChandraRam
              wrote on last edited by
              #8

              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 FileHandle

              HTH [Edit]Had to change since < was intepreted differently[/Edit]

              A 1 Reply Last reply
              0
              • C ChandraRam

                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 FileHandle

                HTH [Edit]Had to change since < was intepreted differently[/Edit]

                A Offline
                A Offline
                Adam m Nelson
                wrote on last edited by
                #9

                That did it! thank you very much

                --Its not broken if it never worked.

                C 1 Reply Last reply
                0
                • A Adam m Nelson

                  That did it! thank you very much

                  --Its not broken if it never worked.

                  C Offline
                  C Offline
                  ChandraRam
                  wrote on last edited by
                  #10

                  Adam.m.Nelson wrote:

                  That did it! thank you very much

                  You are welcome. :)

                  A 1 Reply Last reply
                  0
                  • C ChandraRam

                    Adam.m.Nelson wrote:

                    That did it! thank you very much

                    You are welcome. :)

                    A Offline
                    A Offline
                    Adam m Nelson
                    wrote on last edited by
                    #11

                    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.

                    C 1 Reply Last reply
                    0
                    • A Adam m Nelson

                      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.

                      C Offline
                      C Offline
                      ChandraRam
                      wrote on last edited by
                      #12

                      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

                      A 1 Reply Last reply
                      0
                      • C ChandraRam

                        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

                        A Offline
                        A Offline
                        Adam m Nelson
                        wrote on last edited by
                        #13

                        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.

                        C D 2 Replies Last reply
                        0
                        • A Adam m Nelson

                          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.

                          C Offline
                          C Offline
                          ChandraRam
                          wrote on last edited by
                          #14

                          The Print statements appends a CR+LF to the text... I don't know of a way you could suppress this.

                          A 1 Reply Last reply
                          0
                          • C ChandraRam

                            The Print statements appends a CR+LF to the text... I don't know of a way you could suppress this.

                            A Offline
                            A Offline
                            Adam m Nelson
                            wrote on last edited by
                            #15

                            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.

                            1 Reply Last reply
                            0
                            • A Adam m Nelson

                              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.

                              D Offline
                              D Offline
                              Dave Kreskowiak
                              wrote on last edited by
                              #16

                              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

                              A 2 Replies Last reply
                              0
                              • D Dave Kreskowiak

                                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

                                A Offline
                                A Offline
                                Adam m Nelson
                                wrote on last edited by
                                #17

                                Hey 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.

                                1 Reply Last reply
                                0
                                • D Dave Kreskowiak

                                  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

                                  A Offline
                                  A Offline
                                  Adam m Nelson
                                  wrote on last edited by
                                  #18

                                  Actually, never mind, i re-worked the loop to work around it. Thanks a bunch everyone!! ;)

                                  --Its not broken if it never worked.

                                  1 Reply Last reply
                                  0
                                  Reply
                                  • Reply as topic
                                  Log in to reply
                                  • Oldest to Newest
                                  • Newest to Oldest
                                  • Most Votes


                                  • Login

                                  • Don't have an account? Register

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • World
                                  • Users
                                  • Groups