5 Replies - 560 Views - Last Post: 29 August 2013 - 06:33 PM Rate Topic: -----

#1 Gho5t  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-August 13

Trouble having "streamwrite" to generate a file name automatic

Posted 29 August 2013 - 05:52 PM

Hello all,

I'm new to dreamincode so I will try to follow the rules accordingly.

I am trying to make one of my forms streamwrite the textboxes to a ".txt"
The problem i'm having is making a statement to make a new file name everytime and not the concurrent.

I've looked through MSDN and haven't seen much, also searched through here.

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles createjobbtn.Click

        Using sw As StreamWriter = New StreamWriter("C:\Users\Boutique Windows\Documents\bin\.txt")
            sw.WriteLine(customernametxt.Text)
            sw.WriteLine(customercontacttxt.Text)
            sw.WriteLine(jobaddresstxt.Text)
            sw.Close()

        End Using


As you will see i have specified \.txt"
This only sets the files name to nothing.

What do you recommend i do to make the file name generate every time i use the form?

Is This A Good Question/Topic? 0
  • +

Replies To: Trouble having "streamwrite" to generate a file name automatic

#2 ybadragon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 193
  • View blog
  • Posts: 1,204
  • Joined: 11-May 12

Re: Trouble having "streamwrite" to generate a file name automatic

Posted 29 August 2013 - 06:13 PM

you could use a DateTime stamp in your filename, you could use a counter, random numbers. Anything you really want. At work I use a DateTime stamp Formatted mmDD & runCount so an example file name for my program for todays date and the 3rd time being run would be something like 082903.txt
Was This Post Helpful? 0
  • +
  • -

#3 Gho5t  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-August 13

Re: Trouble having "streamwrite" to generate a file name automatic

Posted 29 August 2013 - 06:16 PM

View Postybadragon, on 29 August 2013 - 06:13 PM, said:

you could use a DateTime stamp in your filename, you could use a counter, random numbers. Anything you really want. At work I use a DateTime stamp Formatted mmDD & runCount so an example file name for my program for todays date and the 3rd time being run would be something like 082903.txt


Oh, so how would i make the file save name = the text added in "jobaddresstxt.text"
For example if i added in "1 Creswick Street" in the textbox, it would save as "1_creswick_street.txt"
Was This Post Helpful? 0
  • +
  • -

#4 ybadragon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 193
  • View blog
  • Posts: 1,204
  • Joined: 11-May 12

Re: Trouble having "streamwrite" to generate a file name automatic

Posted 29 August 2013 - 06:20 PM

You will want to have a String in your program and assign that string to the text you want the save name to be, then instead of using \.txt you would want to use \ then concatenate on the String you created then concatenate on .txt in order to replace the spaces in the given example with _ you will want to look into String.Replace()
Was This Post Helpful? 0
  • +
  • -

#5 Gho5t  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-August 13

Re: Trouble having "streamwrite" to generate a file name automatic

Posted 29 August 2013 - 06:26 PM

View Postybadragon, on 29 August 2013 - 06:20 PM, said:

You will want to have a String in your program and assign that string to the text you want the save name to be, then instead of using \.txt you would want to use \ then concatenate on the String you created then concatenate on .txt in order to replace the spaces in the given example with _ you will want to look into String.Replace()


Thank-you for your input,

Could i ask for a physical example of code as i am not extremely familiar with the syntax but i do understand most concepts behind it.

Thank-you in advance.
Was This Post Helpful? 0
  • +
  • -

#6 ybadragon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 193
  • View blog
  • Posts: 1,204
  • Joined: 11-May 12

Re: Trouble having "streamwrite" to generate a file name automatic

Posted 29 August 2013 - 06:33 PM

I'm not going to write it all out for you, the concepts I suggested are extremely basic when it comes to programming concatenation is VB.Net 101

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1_Click

Dim sFileName As String = ' insert fileName here
Dim sr As StreamWriter = New StreamWriter("C:\Users\Boutique Windows\Documents\bin\" & 'concatenate here' & ".txt"


Was This Post Helpful? 1
  • +
  • -

Page 1 of 1