Text file problem
Text file problem
Text file problem
Text file problem
Text file problem
Text file problem Text file problem Text file problem Text file problem Text file problem Text file problem Text file problem Text file problem
Text file problem Text file problem
Text file problem
Go Back  Xtreme Visual Basic Talk > > > Text file problem


Reply
 
Thread Tools Display Modes
  #1  
Old 12-13-2005, 05:02 AM
spikeymouse's Avatar
spikeymouse spikeymouse is offline
Freshman
 
Join Date: Sep 2005
Posts: 31
Default Text file problem


I'm writing a program in which the users can select an image to be the background for the program, i do this with a textbox where they can type the path to the image, or through a browse button which will put the path in the textbox. Once I press the OK button the program writes the path into a textfile, this works perfectly if the user types the path, when he selects it through the browse button, the path is shown in the textbox but isn't written in the textfile when the OK button is pushed. So here is my code (some words are dutch, if you don't understand just ask ):

the code for the browse button:
Code:
    Private Sub cmdBladeren_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBladeren.Click
        Dim AskFile As New OpenFileDialog

        With AskFile
            .Filter = "jpg(*.jpg) |*.jpg|gif(*.gif)|*.gif"
            .Title = "Selecteer de afbeelding die u als achtergrond wil instellen"
            .CheckFileExists() = True
            .CheckPathExists = True
            .ValidateNames = True
            .DereferenceLinks = True
            .AddExtension = True
            .CheckFileExists = True
            .CheckPathExists = True
            .Multiselect = False
            .ShowReadOnly = False
        End With

        If AskFile.ShowDialog(Me) = DialogResult.OK Then
            txtachtergrond.Text = AskFile.FileName
        End If
        AskFile.Dispose()

    End Sub
The code for the OK button:
Code:
    Public Sub cmdok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdok.Click
        Dim oFile As System.IO.File
        Dim oWrite As System.IO.StreamWriter = New System.IO.StreamWriter("config.cfg")
        Dim strtext As String


        oWrite.WriteLine("[Achtergrond]")
        oWrite.WriteLine(txtachtergrond.Text)

        oWrite.Close()

        Me.Close()

    End Sub
Can anyone help me? I already tried a dutch programmer forum but nobody knew there
__________________
"Why do people depend on each other? In the end you're on your own." - Squall
Seifer: "I hate it when you wish me luck. Save it for the slow students who need it."
Quistis: "All right...Good luck, Seifer." :D
Reply With Quote
  #2  
Old 12-13-2005, 05:07 AM
Iceplug's Avatar
IceplugText file problem Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

Strange...
if you try to show a MessageBox there (right before you write it, do you see the textbox text show up?

MessageBox.Show(txtachtergrond.Text)
oWrite.WriteLine(txtachtergrond.Text)
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #3  
Old 12-13-2005, 05:59 AM
anthony_n's Avatar
anthony_n anthony_n is offline
Senior Contributor
 
Join Date: May 2005
Location: Manchester,England
Posts: 1,293
Default

this might sound like a daft question.

but is the textbox you are entering the string into by hand call txtachtergrond

or do you have any validation code in the key down/up events.
__________________
ADO TUTOR

File IO Tutor
Reply With Quote
  #4  
Old 12-13-2005, 06:24 AM
spikeymouse's Avatar
spikeymouse spikeymouse is offline
Freshman
 
Join Date: Sep 2005
Posts: 31
Default

the messagebox does show the text from the textbox, i put that down there as a test to see if the problem was there, but obviouslly it isn't

the textbox name is really txtachtergrond, the text does appear in the textbox but it isn't written into the textfile
__________________
"Why do people depend on each other? In the end you're on your own." - Squall
Seifer: "I hate it when you wish me luck. Save it for the slow students who need it."
Quistis: "All right...Good luck, Seifer." :D
Reply With Quote
  #5  
Old 12-13-2005, 07:03 AM
anthony_n's Avatar
anthony_n anthony_n is offline
Senior Contributor
 
Join Date: May 2005
Location: Manchester,England
Posts: 1,293
Default

try flushing the stream before closing the connection. this in not making any sense.

you are removing the file before writing to it
__________________
ADO TUTOR

File IO Tutor
Reply With Quote
  #6  
Old 12-13-2005, 07:46 AM
spikeymouse's Avatar
spikeymouse spikeymouse is offline
Freshman
 
Join Date: Sep 2005
Posts: 31
Default

no i'm not removing the file, the content of the file is being written, it's just a test code i'm going to clean it up a bit after i get this to work.

how can i flush the stream?
__________________
"Why do people depend on each other? In the end you're on your own." - Squall
Seifer: "I hate it when you wish me luck. Save it for the slow students who need it."
Quistis: "All right...Good luck, Seifer." :D
Reply With Quote
  #7  
Old 12-13-2005, 08:27 AM
anthony_n's Avatar
anthony_n anthony_n is offline
Senior Contributor
 
Join Date: May 2005
Location: Manchester,England
Posts: 1,293
Default

make sure you kill the file before you write to it

to flush it just do

oWrite.Flush()

just before the oWrite.close()
__________________
ADO TUTOR

File IO Tutor
Reply With Quote
  #8  
Old 12-13-2005, 09:01 AM
spikeymouse's Avatar
spikeymouse spikeymouse is offline
Freshman
 
Join Date: Sep 2005
Posts: 31
Default

flushing didn't work, what do you mean with kill the file before writing it?
__________________
"Why do people depend on each other? In the end you're on your own." - Squall
Seifer: "I hate it when you wish me luck. Save it for the slow students who need it."
Quistis: "All right...Good luck, Seifer." :D
Reply With Quote
  #9  
Old 12-13-2005, 09:13 AM
wayneph's Avatar
waynephText file problem wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

the Kill command in VB6 would delete the file althogether. After having the system delete it, create a new file.

What happens if you specify a full path when you create your StreamWriter. Is it possible that there are multiple copies of the file floating around on the system, and you're watching the the wrong one?
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #10  
Old 12-13-2005, 09:18 AM
anthony_n's Avatar
anthony_n anthony_n is offline
Senior Contributor
 
Join Date: May 2005
Location: Manchester,England
Posts: 1,293
Default

Quote:
Originally Posted by spikeymouse
flushing didn't work, what do you mean with kill the file before writing it?
if System.IO.File.Exists("Filename") then System.IO.File.Delete("Filename")


because you are just overwriting the file it is possable that not all of the file is written over

ie you first write to the fuke

Hello
Anthony

and you write over the file with

Hello Anthony


what you will get is

Hello Anthony
Anthony

this is not your problem tho but can come back and get you.

if the full path does not work then try putting the textbox into a string then write it out
__________________
ADO TUTOR

File IO Tutor
Reply With Quote
  #11  
Old 12-13-2005, 09:54 AM
spikeymouse's Avatar
spikeymouse spikeymouse is offline
Freshman
 
Join Date: Sep 2005
Posts: 31
Default

that's not the problem because it works perfect when you just typ the path in the textbox, the problem is when the path is generated through the open file dialog, then the path appears in the textbox but it won't write it to the textfile, it's really strange
__________________
"Why do people depend on each other? In the end you're on your own." - Squall
Seifer: "I hate it when you wish me luck. Save it for the slow students who need it."
Quistis: "All right...Good luck, Seifer." :D
Reply With Quote
  #12  
Old 12-13-2005, 07:12 PM
nihk nihk is offline
Newcomer
 
Join Date: Nov 2005
Location: Tacloban, Philippines
Posts: 11
Default

i noticed that you have a line that looks like this:

AskFile.Dispose()

try removing that.

the reason: (in my opinion)

txtachtergrond.Text = AskFile.FileName

just passess a reference to AskFile.Filename not the value
so when you dispose AskFile before the sub ends, the value of AskFile.Filename is disposed too.

why do you need to dispose it by the way? it will be automatically disposed when the sub ends.

note: the text above is purely from my imagination. i HAVEN'T tested it.
__________________
Note: the text above is purely from my imagination. i HAVEN'T tested it.
Reply With Quote
  #13  
Old 12-14-2005, 08:53 AM
spikeymouse's Avatar
spikeymouse spikeymouse is offline
Freshman
 
Join Date: Sep 2005
Posts: 31
Default

this didn't make any difference, i guess your imagination was wrong
__________________
"Why do people depend on each other? In the end you're on your own." - Squall
Seifer: "I hate it when you wish me luck. Save it for the slow students who need it."
Quistis: "All right...Good luck, Seifer." :D
Reply With Quote
  #14  
Old 12-14-2005, 02:54 PM
Iceplug's Avatar
IceplugText file problem Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

Now... does it work if you put something in from the dialog into the textbox and then type something else into it?
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #15  
Old 12-14-2005, 02:57 PM
spikeymouse's Avatar
spikeymouse spikeymouse is offline
Freshman
 
Join Date: Sep 2005
Posts: 31
Default

i just did a small test and it seems that when i use the browse button, nothing is written to the text file, it's like the browse button stops all code from the OK button :s
__________________
"Why do people depend on each other? In the end you're on your own." - Squall
Seifer: "I hate it when you wish me luck. Save it for the slow students who need it."
Quistis: "All right...Good luck, Seifer." :D
Reply With Quote
  #16  
Old 12-14-2005, 02:58 PM
anthony_n's Avatar
anthony_n anthony_n is offline
Senior Contributor
 
Join Date: May 2005
Location: Manchester,England
Posts: 1,293
Default

put both into a string then write them out to the file and see if that works
__________________
ADO TUTOR

File IO Tutor
Reply With Quote
  #17  
Old 12-14-2005, 03:25 PM
spikeymouse's Avatar
spikeymouse spikeymouse is offline
Freshman
 
Join Date: Sep 2005
Posts: 31
Default

allready tried it, doesn't make a difference at all.
__________________
"Why do people depend on each other? In the end you're on your own." - Squall
Seifer: "I hate it when you wish me luck. Save it for the slow students who need it."
Quistis: "All right...Good luck, Seifer." :D
Reply With Quote
  #18  
Old 12-14-2005, 03:37 PM
spikeymouse's Avatar
spikeymouse spikeymouse is offline
Freshman
 
Join Date: Sep 2005
Posts: 31
Default

i uploaded my source files in a rar file, feel free to experiment with it but please find me the solution, it's quite important. this program is a big task for school so i really need the answer.
Don't forget to edit the config.cfg file before you try to open it (it's in dutch, i hope you'll understand).

http://users.telenet.be/spikeymouse/program.rar
__________________
"Why do people depend on each other? In the end you're on your own." - Squall
Seifer: "I hate it when you wish me luck. Save it for the slow students who need it."
Quistis: "All right...Good luck, Seifer." :D
Reply With Quote
  #19  
Old 12-15-2005, 02:00 AM
anthony_n's Avatar
anthony_n anthony_n is offline
Senior Contributor
 
Join Date: May 2005
Location: Manchester,England
Posts: 1,293
Default

can you remove the dll's and exe
__________________
ADO TUTOR

File IO Tutor
Reply With Quote
  #20  
Old 12-15-2005, 04:39 AM
spikeymouse's Avatar
spikeymouse spikeymouse is offline
Freshman
 
Join Date: Sep 2005
Posts: 31
Default

okay it's done, i uploaded it again without the exe and dll's, the bin folder is still there though because my config file is in it.

http://users.telenet.be/spikeymouse/program.rar
__________________
"Why do people depend on each other? In the end you're on your own." - Squall
Seifer: "I hate it when you wish me luck. Save it for the slow students who need it."
Quistis: "All right...Good luck, Seifer." :D
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Text file problem
Text file problem
Text file problem Text file problem
Text file problem
Text file problem
Text file problem Text file problem Text file problem Text file problem Text file problem Text file problem Text file problem
Text file problem
Text file problem
 
Text file problem
Text file problem
 
-->