Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 2008 > Visual Basic 2008 Essentials
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Visual Basic 2008 Essentials If you are new to Visual Basic programming with version 2008, this is the place to start your questions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2008 Essentials section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 7th, 2009, 12:41 PM
Authorized User
 
Join Date: Jun 2008
Location: , , .
Posts: 33
Thanks: 2
Thanked 0 Times in 0 Posts
Default Creating a txt file

I'm trying to save a text file with data that the user has put into textboxes on a form. When they click the save button I want a txt file to be saved in a specified folder on my computer automatically. I would like the name of the txt file to be named the same as one of the textboxes on the form.

Currently my code is set so that the txt file is created and saves the data from the text boxes just fine. However the code I have right now brings up a dialog box after I click my save button and has me choose where to save it on the computer and what to name the file. How do I write code to make this step automatic?

Thanks

Here is my code:

PrivateSub WriteRecipeFile()
'It is in these first few line of code that I need the help with
Dim Recipe As StreamWriter
Dim results As DialogResult
results = SaveFileDialog1.ShowDialog
If results = DialogResult.OK Then
Recipe = New StreamWriter(SaveFileDialog1.FileName, False)
'Everything Below here works great
Recipe.Write(RecipeName.Text)
Recipe.Write(vbCrLf)
Recipe.Write(Task1.Text)
Recipe.Write(
",")
If Task1.Text = "Vacuum"Then
Recipe.Write(Val(vac1))
ElseIf Task1.Text = "Temperature"Then
Recipe.Write(Task1Temp.Text)
ElseIf Task1.Text = "Wait"Then
Recipe.Write(Task1Wait.Text)
ElseIf Task1.Text = "Voltage"Then
Recipe.Write(Task1Volt.Text)
ElseIf Task1.Text = "Vent"Then
Recipe.Write(Val(ven1))
Else
EndIf
Recipe.Write(vbCrLf)
Recipe.Write(Task2.Text)
Recipe.Write(
",")
If Task2.Text = "Vacuum"Then
Recipe.Write(Val(vac2))
ElseIf Task2.Text = "Temperature"Then
Recipe.Write(Task2Temp.Text)
ElseIf Task2.Text = "Wait"Then
Recipe.Write(Task2Wait.Text)
ElseIf Task2.Text = "Voltage"Then
Recipe.Write(Task2Volt.Text)
ElseIf Task2.Text = "Vent"Then
Recipe.Write(Val(ven2))
Else
EndIf
Recipe.Write(vbCrLf)
Recipe.Write(Task3.Text)
Recipe.Write(
",")
If Task3.Text = "Vacuum"Then
Recipe.Write(Val(vac3))
ElseIf Task3.Text = "Temperature"Then
Recipe.Write(Task3Temp.Text)
ElseIf Task3.Text = "Wait"Then
Recipe.Write(Task3Wait.Text)
ElseIf Task3.Text = "Voltage"Then
Recipe.Write(Task3Volt.Text)
ElseIf Task3.Text = "Vent"Then
Recipe.Write(Val(ven3))
Else
EndIf
Recipe.Write(vbCrLf)
Recipe.Write(Task4.Text)
Recipe.Write(
",")
If Task4.Text = "Vacuum"Then
Recipe.Write(Val(vac4))
ElseIf Task4.Text = "Temperature"Then
Recipe.Write(Task4Temp.Text)
ElseIf Task4.Text = "Wait"Then
Recipe.Write(Task4Wait.Text)
ElseIf Task4.Text = "Voltage"Then
Recipe.Write(Task4Volt.Text)
ElseIf Task4.Text = "Vent"Then
Recipe.Write(Val(ven4))
Else
EndIf
Recipe.Write(vbCrLf)
Recipe.Write(Task5.Text)
Recipe.Write(
",")
If Task5.Text = "Vacuum"Then
Recipe.Write(Val(vac5))
ElseIf Task5.Text = "Temperature"Then
Recipe.Write(Task5Temp.Text)
ElseIf Task5.Text = "Wait"Then
Recipe.Write(Task5Wait.Text)
ElseIf Task5.Text = "Voltage"Then
Recipe.Write(Task5Volt.Text)
ElseIf Task5.Text = "Vent"Then
Recipe.Write(Val(ven5))
Else
EndIf
Recipe.Write(vbCrLf)
Recipe.Write(Task6.Text)
Recipe.Write(
",")
If Task6.Text = "Vacuum"Then
Recipe.Write(Val(vac6))
ElseIf Task6.Text = "Temperature"Then
Recipe.Write(Task6Temp.Text)
ElseIf Task6.Text = "Wait"Then
Recipe.Write(Task6Wait.Text)
ElseIf Task6.Text = "Voltage"Then
Recipe.Write(Task6Volt.Text)
ElseIf Task6.Text = "Vent"Then
Recipe.Write(Val(ven6))
Else
EndIf
Recipe.Write(vbCrLf)
Recipe.Write(Task7.Text)
Recipe.Write(
",")
If Task7.Text = "Vacuum"Then
Recipe.Write(Val(vac7))
ElseIf Task7.Text = "Temperature"Then
Recipe.Write(Task7Temp.Text)
ElseIf Task7.Text = "Wait"Then
Recipe.Write(Task7Wait.Text)
ElseIf Task7.Text = "Voltage"Then
Recipe.Write(Task7Volt.Text)
ElseIf Task7.Text = "Vent"Then
Recipe.Write(Val(ven7))
Else
EndIf
Recipe.Write(vbCrLf)
Recipe.Write(Task8.Text)
Recipe.Write(
",")
If Task8.Text = "Vacuum"Then
Recipe.Write(Val(vac8))
ElseIf Task8.Text = "Temperature"Then
Recipe.Write(Task8Temp.Text)
ElseIf Task8.Text = "Wait"Then
Recipe.Write(Task8Wait.Text)
ElseIf Task8.Text = "Voltage"Then
Recipe.Write(Task8Volt.Text)
ElseIf Task8.Text = "Vent"Then
Recipe.Write(Val(ven8))
Else
EndIf
Recipe.Write(vbCrLf)
Recipe.Write(Task9.Text)
Recipe.Write(
",")
If Task9.Text = "Vacuum"Then
Recipe.Write(Val(vac9))
ElseIf Task9.Text = "Temperature"Then
Recipe.Write(Task9Temp.Text)
ElseIf Task9.Text = "Wait"Then
Recipe.Write(Task9Wait.Text)
ElseIf Task9.Text = "Voltage"Then
Recipe.Write(Task9Volt.Text)
ElseIf Task9.Text = "Vent"Then
Recipe.Write(Val(ven9))
Else
EndIf
Recipe.Write(vbCrLf)
Recipe.Write(Task10.Text)
Recipe.Write(
",")
If Task10.Text = "Vacuum"Then
Recipe.Write(Val(vac10))
ElseIf Task10.Text = "Temperature"Then
Recipe.Write(Task10Temp.Text)
ElseIf Task10.Text = "Wait"Then
Recipe.Write(Task10Wait.Text)
ElseIf Task10.Text = "Voltage"Then
Recipe.Write(Task10Volt.Text)
ElseIf Task10.Text = "Vent"Then
Recipe.Write(Val(ven10))
Else
EndIf
Recipe.Write(vbCrLf)
Recipe.Write(Task11.Text)
Recipe.Write(
",")
If Task11.Text = "Vacuum"Then
Recipe.Write(Val(vac11))
ElseIf Task11.Text = "Temperature"Then
Recipe.Write(Task11Temp.Text)
ElseIf Task11.Text = "Wait"Then
Recipe.Write(Task11Wait.Text)
ElseIf Task11.Text = "Voltage"Then
Recipe.Write(Task11Volt.Text)
ElseIf Task11.Text = "Vent"Then
Recipe.Write(Val(ven11))
Else
EndIf
Recipe.Write(vbCrLf)
Recipe.Write(Task12.Text)
Recipe.Write(
",")
If Task12.Text = "Vacuum"Then
Recipe.Write(Val(vac12))
ElseIf Task12.Text = "Temperature"Then
Recipe.Write(Task12Temp.Text)
ElseIf Task12.Text = "Wait"Then
Recipe.Write(Task12Wait.Text)
ElseIf Task12.Text = "Voltage"Then
Recipe.Write(Task12Volt.Text)
ElseIf Task12.Text = "Vent"Then
Recipe.Write(Val(ven12))
Else
EndIf
Recipe.Write(vbCrLf)
Recipe.Write(Task13.Text)
Recipe.Write(
",")
If Task13.Text = "Vacuum"Then
Recipe.Write(Val(vac13))
ElseIf Task13.Text = "Temperature"Then
Recipe.Write(Task13Temp.Text)
ElseIf Task13.Text = "Wait"Then
Recipe.Write(Task13Wait.Text)
ElseIf Task13.Text = "Voltage"Then
Recipe.Write(Task13Volt.Text)
ElseIf Task13.Text = "Vent"Then
Recipe.Write(Val(ven13))
Else
EndIf
Recipe.Write(vbCrLf)
Recipe.Write(Task14.Text)
Recipe.Write(
",")
If Task14.Text = "Vacuum"Then
Recipe.Write(Val(vac14))
ElseIf Task14.Text = "Temperature"Then
Recipe.Write(Task14Temp.Text)
ElseIf Task14.Text = "Wait"Then
Recipe.Write(Task14Wait.Text)
ElseIf Task14.Text = "Voltage"Then
Recipe.Write(Task14Volt.Text)
ElseIf Task14.Text = "Vent"Then
Recipe.Write(Val(ven14))
Else
EndIf
Recipe.Write(vbCrLf)
Recipe.Write(Task15.Text)
Recipe.Write(
",")
If Task15.Text = "Vacuum"Then
Recipe.Write(Val(vac15))
ElseIf Task15.Text = "Temperature"Then
Recipe.Write(Task15Temp.Text)
ElseIf Task15.Text = "Wait"Then
Recipe.Write(Task15Wait.Text)
ElseIf Task15.Text = "Voltage"Then
Recipe.Write(Task15Volt.Text)
ElseIf Task15.Text = "Vent"Then
Recipe.Write(Val(ven15))
Else
EndIf
Recipe.Close()
EndIf
EndSub
Reply With Quote
  #2 (permalink)  
Old January 7th, 2009, 08:44 PM
Friend of Wrox
Points: 3,060, Level: 23
Points: 3,060, Level: 23 Points: 3,060, Level: 23 Points: 3,060, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: , , .
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi

You can remove the lines that shows the SaveFileDialog and insert something similar

sText = TextBox1.text & ".txt"
sPAth = "c:\temp\"
sFile = sPath & sText
Recipe = New StreamWriter(sFile, False)

instead of this

results = SaveFileDialog1.ShowDialog
If results = DialogResult.OK Then
Recipe = New StreamWriter(SaveFileDialog1.FileName, False)
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
Reply With Quote
  #3 (permalink)  
Old January 8th, 2009, 01:24 PM
Authorized User
 
Join Date: Jun 2008
Location: , , .
Posts: 33
Thanks: 2
Thanked 0 Times in 0 Posts
Default Thanks

Thank you for the help. It works great.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
read any ".txt" file RodrigoGuteriez C# 3 November 18th, 2008 01:07 PM
Reading txt file umeshtheone SQL Server 2000 9 May 15th, 2007 12:43 AM
Reading a txt file AlphaX Beginning VB 6 2 February 20th, 2006 11:22 PM
export to .txt file meimy Pro VB.NET 2002/2003 0 May 31st, 2004 02:24 AM



All times are GMT -4. The time now is 04:15 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.