::BulletMagneT::

I have a program that opens up a file called a MNU file, that contains info for a menu for a game (button fonts and such). It reads the text fine when you open it, and displays the text correctly, it also saves as a MNU file, but does not write all the text, just an empty file.

If CheckBox1.Checked Then

TextBox1.Text.Replace("ARGB=AMBER_NORMAL,255,240,98,28", "ARGB=WHITE,255,255,255,255")

Dim s As New SaveFileDialog

s.Filter = "DF2 MNU Files (*.MNU)|*.MNU"

If CurrentFilename.Length = 0 Then

If s.ShowDialog = Windows.Forms.DialogResult.OK Then

CurrentFilename = s.FileName

End If

End If

If CurrentFilename.Length > 0 Then

My.Computer.FileSystem.WriteAllText(CurrentFilename, Me.TextBox1.Text, False)

End If



Re: Visual Basic Express Edition Save as "MNU" file and write text.

pastmaster

I've a different problem unlike yours. I save it in a *.epd extension, stands for EditPad Document. But, when I close my editor and double click the file I saved, the contents are not getting displayed. Did you manage to show the contents of the file when you double click it





Re: Visual Basic Express Edition Save as "MNU" file and write text.

nobugz

Set a breakpoint on the WriteAllText() call. When it hit, inspect the value of the textbox. If it is empty but you see the text on the screen, add "Me.Show()" to the code to see the cause of your problem.





Re: Visual Basic Express Edition Save as "MNU" file and write text.

NewProgrammer

I found it will save if i set the file path destination, but not when using a save file dialog



Re: Visual Basic Express Edition Save as "MNU" file and write text.

LennardF1989

You should try an other writing method, here's a well used function by me, I optimized it a bit for your using:

Code Snippet

'Add this to the top of the file you put the function in

Imports System.IO

'The actual function

Private Sub WriteFile(ByVal Contents As String, ByVal FileName As String, ByVal Location As String, ByVal AppendFile As Boolean)

Dim File As String = Location & "\" & FileName

Dim FileContents As String

Dim StreamReader As StreamReader

Dim StreamWriter As StreamWriter

Dim FileInfo As New IO.FileInfo(File)

If AppendFile = True Then

If FileInfo.Exists = True Then

StreamReader = New StreamReader(File)

FileContents = StreamReader.ReadToEnd()

StreamReader.Close()

End If

End If

StreamWriter = New StreamWriter(File)

If FileContents = "" Then

StreamWriter.WriteLine(Contents)

StreamWriter.Close()

Else

StreamWriter.Write(FileContents)

StreamWriter.WriteLine(Contents)

StreamWriter.Close()

End If

End Sub

Hope this helps a bit...

You use it like: WriteFile("Contents I want in the file", "Test.mnu", Application.StartupPath, False)

BTW. When you want to use New Lines, you would have to include in eather the function or the Contents string by using vbNewLine.

Regards,

Lennard