What's new

[VB.Net] Need help.

XoX

XoX

Getting There
Messages
1,415
Reaction score
237
Points
210
Code:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not File.Exists("settings.xox") Then
MessageBox.Show("1")
File.Create(Directory.GetCurrentDirectory & "settings.xox")
Dim CreateSettings As New StreamWriter("settings.xox")
CreateSettings.WriteLine("10")
CreateSettings.WriteLine("10")
MessageBox.Show("2")
End If
Dim OpenSettings As New StreamReader("settings.xox")
MessageBox.Show("3")
End Sub

I added these Messageboxes for Debug reasons.
If the file (settings.xox) doesnt exist, it is created, but empty. I get to see the Messageboxes 1 and 2, 3 doesn't appear.
If the file exists, none of the messageboxes show.
This doesn't make sense to me at all, can you guys help me please.
 
Calamity

Calamity

Retired
Retired
Messages
6,704
Reaction score
1,159
Points
650
I just cut/pasted the code to look at it..

When you create the 'CreateSettings' StreamWriter, you're loading that file into memory. If the file doesn't exist, then it's opened in memory, and will stay open unless you call the close function on it (CreateSettings.Close()).

If you're ever working with Stream's, close them after you're done using them.
 
XoX

XoX

Getting There
Messages
1,415
Reaction score
237
Points
210
Oops, I haven't used streams in a while. Forgot all about that. Thank you.
 

Similar threads

Top Bottom
Login
Register