|
-
Dec 9th, 2012, 04:16 PM
#1
Thread Starter
New Member
[RESOLVED] Creating and Writing to Text File
I'm having trouble creating a text file, and writing a stored integer to it as a save text file.
What I have is:
(I've imported System.IO already)
Dim id As Integer
Dim writer As StreamWriter
writer = File.CreateText("save.txt")
writer.WriteLine(id)
writer.Flush()
writer.Close()
When I run my program and select save, it doesn't create a save.txt file. What am I doing wrong?
-
Dec 9th, 2012, 04:37 PM
#2
Re: Creating and Writing to Text File
It certainly does create the file. It's just that you don't know where to look. Try specifying a directory and look there!
writer = File.CreateText("C:\save.txt")
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Dec 9th, 2012, 04:46 PM
#3
Thread Starter
New Member
Re: Creating and Writing to Text File
I've tried specifying a directory, and that doesn't work either.
If no directory is listed, it should save the file in the same directory that the app is run from (in this case my Debug folder) and it isn't there either.
-
Dec 9th, 2012, 04:52 PM
#4
Re: Creating and Writing to Text File
Then your code isn't executing at all ...
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Dec 9th, 2012, 04:54 PM
#5
Re: Creating and Writing to Text File
Not quite so Webberjo. If no path is specified, it will save the file in the current working directory. The default is the same as the folder as the .exe but it can be changed.
I would suggest (if you haven't already done it) use Windows search to search for the filename you think you should have created to find out which directory it is actually being saved in.
Also, you could use Application.StartupPath & "\save.txt" to ensure it is in the same directory as the .exe
-
Dec 9th, 2012, 04:58 PM
#6
Thread Starter
New Member
Re: Creating and Writing to Text File
Stupid me, for some reason the handle on my save button was missing. No wonder nothing was happening. 
Thanks for the assistance!
-
Dec 9th, 2012, 05:25 PM
#7
Re: Creating and Writing to Text File
 Originally Posted by Webberjo
Stupid me, for some reason the handle on my save button was missing. No wonder nothing was happening. 
Thanks for the assistance!
Most likely because you deleted the control from the form then added it back from the toolbox and assumed the button event would still work like it would if you were using older classic VB.
When you delete a control from a form VB removes all the Handle clauses from the created subs for the control, but the subs and the code in them remain.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|