Why empty textfile?

BrechtLS

Active member
Joined
Apr 5, 2006
Messages
32
Location
Belgium
Programming Experience
1-3
Is there someone who knows why the textfile I create this way is empty?:
VB.NET:
Dim oFile As System.IO.File
Dim oWrite As System.IO.StreamWriter
oWrite = oFile.CreateText("c:\Duiven\" & txtNG.Text & "_" & txtRGN.Text & "-" & txtRGJ.Text & ".txt")
oWrite.WriteLine(txtNG.Text & "<" & txtRGN.Text & "<" & txtRGJ.Text & "<" & cboKleur.Text & "<" & intValue & "<" & txtNGMG.Text & "<" & txtRGMG.Text & "<" & txtRGMGJ.Text & "<" & txtND1OA.Text & "<" & txtRD1OA.Text & "<" & txtRD1OAJ.Text & "<" & txtND2OA.Text & "<" & txtRD2OA.Text & "<" & txtRD2OAJ.Text & "<" & txtGVA.Text & "<" & txtPA.Text & "<" & rtfAndere.Text & "<" & strIG & "<" & strN & "<" & strU & "<" & intIGT & "<" & intNT & "<" & intUT)
 
Thanks it works now!
Do I have to close the readstream also?
And another question I have is how can you convert the text in the file to a string?? I have tried to convert it but he gives an error. Is there a way to convert that so I can use the text from the file in my application??
 
Yes, you should always close streams you open.
Convert what? StreamReader have ReadLine and ReadToEnd methods that return strings.
 
Ah, I didn't see that you can do it that way.
Thanks a lot!
 
Just a note. You don't EVER create instances of the IO.File class. All useful members are Shared so you call them on the class itself, not an instance, e.g.
VB.NET:
oWrite = IO.File.CreateText("c:\Duiven\" & txtNG.Text & "_" & txtRGN.Text & "-" & txtRGJ.Text & ".txt")
 
An instance of a class, an object, is created by using the New keyword. (refer the infamous 'Object reference not set to an instance of an object')
How much memory was allocated for this type with the use if Dim statement I don't know, but I agree on the general usage of shared members.
:)
 
Back
Top