Results 1 to 6 of 6

Thread: [RESOLVED] Automating text file name

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Location
    Ireland
    Posts
    85

    Resolved [RESOLVED] Automating text file name

    I have a program, and writes data to a text file... with a template inside...

    All works fine, and saves fine...

    I'm wondering, how could I automate the filename it saves?

    Currently it saves the text file as NewOrder.txt

    I would like it to now realise that there is a NewOrder.txt already there, and save as NewOrder1.txt

    Then when the program is closed, and I go to do a new one, it will say ok NewOrder2.txt

    Hoping this is possible, I've been reading up on my.settings but I can't really find what I'm looking for...

    Thanks!

  2. #2
    Lively Member
    Join Date
    Sep 2009
    Posts
    64

    Re: Automating text file name

    Dont really need to look at form .settings
    You would need to maybe write a small function

    take you base file name as string
    add an integer
    and add a loop using the System.IO.File.Exists component. if value is true then increase the integer by one

    Then you can call your function in your save dialogue or streamwriter

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Location
    Ireland
    Posts
    85

    Re: Automating text file name

    Sounds lovely, any start on the code? I can't really understand that to be honest with you... Very very new to all of it

  4. #4
    Lively Member
    Join Date
    Sep 2009
    Posts
    64

    Re: Automating text file name

    you could show us the code so far, and maybe change it simply at first so that you are using System.IO.File.Exists, if you google that you start to get some idea of how to implement it

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Location
    Ireland
    Posts
    85

    Re: Automating text file name

    I'll google that now sir! Thanks again...

    vb Code:
    1. Dim txtFile As String = IO.File.ReadAllText("template.txt")
    2.         txtFile = txtFile.Replace("[left eye]", LeftEyeTextBox.Text)
    3.         txtFile = txtFile.Replace("[right eye]", RightEyeTextBox.Text)
    4.         IO.File.WriteAllText("NewOrder.txt", txtFile)

    That's my code though... but I'll read up on that now

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Location
    Ireland
    Posts
    85

    Re: Automating text file name

    Great, Got it working with IO.File.Exists thanks again.

Tags for this Thread

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