C
Christian Blackburn
Hi Gang,
I've created a text-based file format. Once I've generated the text to save
the file is as it should be in the debug window. However once I write it to
a file a " is added to the beginning and a ", to the end. Can somebody
explain why? I'm using VB2003.
Thanks in advance for any help,
Christian Blackburn
Here's my code:
Public Sub SaveGame(ByVal strDocument As String, Optional ByVal
bolShow_Dialog As Boolean = False)
'Saves the current game with or without showing a save as dialog
'Stores the Document Text to be saved
Dim strText As String
'Used to cycle through all the value X and Y coordinates of the table's
lights
Dim X As Integer
Dim Y As Integer
'If the user has requested to show a dialog or no file was specified show
the save dialog
If bolShow_Dialog = True Or strDocument = "" Then
objfrmMain.SaveFileDialog.Title = IIf(strDocument = "", "Save Game",
"Save Game As")
objfrmMain.SaveFileDialog.FileName = strDocument
If objfrmMain.SaveFileDialog.ShowDialog() = DialogResult.OK Then
strDocument = objfrmMain.SaveFileDialog.FileName
Else
Exit Sub
End If
End If
strText = "OriginalDocumentName=" & strDocument & ";" & vbNewLine & _
"OriginalDocumentModified=" & DateTime.Now & ";" & vbNewLine & _
"ProgramTitle=" & strAPP_TITLE & ";" & vbNewLine & _
"ProgramPath=" & Application.ExecutablePath & ";" & vbNewLine & _
"ProgramDateTime=" & FileDateTime(Application.ExecutablePath) & ";" &
vbNewLine & _
"DocumentVersion=" & "1.03;" & vbNewLine & _
"PuzzleSize=" & "5,5;"
For X = 0 To 4
For Y = 0 To 4
If bolOn(X, Y) = True Then
strText = strText & vbNewLine & X & "," & Y & "=" & "1;"
Else
strText = strText & vbNewLine & X & "," & Y & "=" & "0;"
End If
Next
Next
Debug.WriteLine(vbNewLine & strDocument & ":")
Debug.Write(strText)
'Opens our document for output, with write only access, and locks the
writability until we're done
FileOpen(1, strDocument, OpenMode.Output, OpenAccess.Write,
OpenShare.LockWrite)
'Writes the strText text to the file
FileSystem.Write(1, strText)
'Closes our handle to the file, allowing all programs to edit the file
FileClose(1)
strFile = strDocument
'Disables the Save Menu Option and Toolbar Button, because we just saved the
file so there couldn't be anything
'worth saving yet
objfrmMain.mnuSave.Enabled = False
objfrmMain.ToolBar.Buttons(2).Enabled = False
objfrmMain.StatusBar.Text = strDocument & " saved."
End Sub
I've created a text-based file format. Once I've generated the text to save
the file is as it should be in the debug window. However once I write it to
a file a " is added to the beginning and a ", to the end. Can somebody
explain why? I'm using VB2003.
Thanks in advance for any help,
Christian Blackburn
Here's my code:
Public Sub SaveGame(ByVal strDocument As String, Optional ByVal
bolShow_Dialog As Boolean = False)
'Saves the current game with or without showing a save as dialog
'Stores the Document Text to be saved
Dim strText As String
'Used to cycle through all the value X and Y coordinates of the table's
lights
Dim X As Integer
Dim Y As Integer
'If the user has requested to show a dialog or no file was specified show
the save dialog
If bolShow_Dialog = True Or strDocument = "" Then
objfrmMain.SaveFileDialog.Title = IIf(strDocument = "", "Save Game",
"Save Game As")
objfrmMain.SaveFileDialog.FileName = strDocument
If objfrmMain.SaveFileDialog.ShowDialog() = DialogResult.OK Then
strDocument = objfrmMain.SaveFileDialog.FileName
Else
Exit Sub
End If
End If
strText = "OriginalDocumentName=" & strDocument & ";" & vbNewLine & _
"OriginalDocumentModified=" & DateTime.Now & ";" & vbNewLine & _
"ProgramTitle=" & strAPP_TITLE & ";" & vbNewLine & _
"ProgramPath=" & Application.ExecutablePath & ";" & vbNewLine & _
"ProgramDateTime=" & FileDateTime(Application.ExecutablePath) & ";" &
vbNewLine & _
"DocumentVersion=" & "1.03;" & vbNewLine & _
"PuzzleSize=" & "5,5;"
For X = 0 To 4
For Y = 0 To 4
If bolOn(X, Y) = True Then
strText = strText & vbNewLine & X & "," & Y & "=" & "1;"
Else
strText = strText & vbNewLine & X & "," & Y & "=" & "0;"
End If
Next
Next
Debug.WriteLine(vbNewLine & strDocument & ":")
Debug.Write(strText)
'Opens our document for output, with write only access, and locks the
writability until we're done
FileOpen(1, strDocument, OpenMode.Output, OpenAccess.Write,
OpenShare.LockWrite)
'Writes the strText text to the file
FileSystem.Write(1, strText)
'Closes our handle to the file, allowing all programs to edit the file
FileClose(1)
strFile = strDocument
'Disables the Save Menu Option and Toolbar Button, because we just saved the
file so there couldn't be anything
'worth saving yet
objfrmMain.mnuSave.Enabled = False
objfrmMain.ToolBar.Buttons(2).Enabled = False
objfrmMain.StatusBar.Text = strDocument & " saved."
End Sub