Results 1 to 5 of 5

Thread: [RESOLVED] Saving as .bat...

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2009
    Location
    Norway
    Posts
    12

    Resolved [RESOLVED] Saving as .bat...

    Hello!
    I'm having this problem...
    I've made a sort of a notpad, and a MenuStrip with the button Run... but how do I get it to save the textfile in f.ex C:\. Like C:\thing.bat?
    Please help!

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Saving as .bat...

    Lets say your notepad app has a textbox where the user types the text and it is called textbox1.

    You can use code like this to save the text from that textbox to a file

    Code:
    Dim myFileName As String = "C:\somefile.bat"
    My.Computer.FileSystem.WriteAllText(myFileName, textbox1.text, False)
    of course this means the file will be "C:\somefile.bat" everytime since it is hard coded. What you likely want to do, is make use of the "SaveFileDialog" component in the toolbox, so you could bring up a save dialog and have the user select the path and name the file whatever they want. You would then use that filename instead of the hard coded one to save the text to a bat file.

  3. #3
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Saving as .bat...

    Add a batch thing to your SaveFileDialog.
    vb Code:
    1. o_dl.Filter = "Text Document (*.txt)|*.txt|Batch File (*.bat)|*.bat|All Files (*.*)|*.*"

  4. #4

    Thread Starter
    New Member
    Join Date
    Apr 2009
    Location
    Norway
    Posts
    12

    Re: Saving as .bat...

    Thank you!
    I think the code is okay, because I just want it to be saved somewhere, it doesn't matter! The name doesn't matter either! It's just to try out the file that I've made, and the delete it!

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2009
    Location
    Norway
    Posts
    12

    Re: Saving as .bat...

    Thanks for the answer, but I just wanted it to be saved as a .bat without any more actions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width