473,387 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Why are quotes being added to my document when using FileSystem.Write(1)?

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
Nov 20 '05 #1
4 2526
[Hi Gang,
I thought I should mention way the file winds up looking:]

"OriginalDocumentName=D:\Current.EverybodyOn;
OriginalDocumentModified=9/10/2003 9:57:24 PM;
ProgramTitle=Everybody On;
ProgramPath=D:\Programming\VB.Net\EveryBody On\Source\Chapter2\bin\Everybody
On.exe;
ProgramDateTime=9/10/2003 9:57:18 PM;
DocumentVersion=1.03;
PuzzleSize=5,5;
0,0=1;
0,1=0;
0,2=0;
0,3=1;
0,4=0;
1,0=0;
1,1=1;
1,2=1;
1,3=1;
1,4=1;
2,0=0;
2,1=1;
2,2=0;
2,3=0;
2,4=1;
3,0=0;
3,1=0;
3,2=1;
3,3=0;
3,4=1;
4,0=1;
4,1=1;
4,2=1;
4,3=1;
4,4=1;",
[Here's how it should look:]

OriginalDocumentName=D:\Current.EverybodyOn;
OriginalDocumentModified=9/10/2003 9:57:24 PM;
ProgramTitle=Everybody On;
ProgramPath=D:\Programming\VB.Net\EveryBody On\Source\Chapter2\bin\Everybody
On.exe;
ProgramDateTime=9/10/2003 9:57:18 PM;
DocumentVersion=1.03;
PuzzleSize=5,5;
0,0=1;
0,1=0;
0,2=0;
0,3=1;
0,4=0;
1,0=0;
1,1=1;
1,2=1;
1,3=1;
1,4=1;
2,0=0;
2,1=1;
2,2=0;
2,3=0;
2,4=1;
3,0=0;
3,1=0;
3,2=1;
3,3=0;
3,4=1;
4,0=1;
4,1=1;
4,2=1;
4,3=1;
4,4=1;
Nov 20 '05 #2
Cor

"Christian Blackburn"
I did not real search all of your code, but I think the error is in this
part.
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

When I see it right, you say everytime
a = a + n
a = a + n + a + n + a + n
etc.
I think you did mean something more like:
a = n + n + n
Dim temp as string
For X = 0 To 4
For Y = 0 To 4
If bolOn(X, Y) = True Then
temp = temp & vbNewLine & X & "," & Y & "=" & "1;"
Else
temp = temp & vbNewLine & X & "," & Y & "=" & "0;"
End If
Next
Next
strText = strText & temp

I hope this helps a little bit.
Cor

Nov 20 '05 #3
"Christian Blackburn" <Christian@Damn@Sp**@Hotmail.com> schrieb
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

[...]

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)


Have a look at the docs for FileSystem.Write. Whenever you write a string,
<"> is written before and after. You can write several values in the same
line into the file. They are separated by a ",". If your string also
contains a comma you can distinguish between the comma within a string and
the comma separating the values because the string is put in quotes. Use
FileSystem.Print instead (see it's docs for more information).

You can also create a FileStream (System.IO.FileStream) instead.

See also:

<F1>
Visual Studio.NET
Visual Basic and Visual C#
Reference
Visual Basic language
Visual Basic Language Tour
-> Processing drives, folders and files
.NET Framework
Programming with .NET Framework
-> Working with I/O

--
Armin

Nov 20 '05 #4
Yay,
Thanks again Armin. Your FileSystem.Print suggestion worked great.
Cheers,
Christian

"Armin Zingler" <az*******@freenet.de> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
"Christian Blackburn" <Christian@Damn@Sp**@Hotmail.com> schrieb
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

[...]

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)


Have a look at the docs for FileSystem.Write. Whenever you write a string,
<"> is written before and after. You can write several values in the same
line into the file. They are separated by a ",". If your string also
contains a comma you can distinguish between the comma within a string and
the comma separating the values because the string is put in quotes. Use
FileSystem.Print instead (see it's docs for more information).

You can also create a FileStream (System.IO.FileStream) instead.

See also:

<F1>
Visual Studio.NET
Visual Basic and Visual C#
Reference
Visual Basic language
Visual Basic Language Tour
-> Processing drives, folders and files
.NET Framework
Programming with .NET Framework
-> Working with I/O

--
Armin

Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: John Norvell | last post by:
I just noticed that recently the javascript I was using to format and display the last modified date of my web page is always reporting the current date instead. It used to work fine. This is true...
1
by: scott | last post by:
Can someone help me my quotes in LISTING 2 below? LISTING 1 works fine in HTML, but I'm having trouble with quotes in LISTING 2 near the javascript code when trying to response write the entire...
2
by: asd987 | last post by:
Hi, I use document.write in a HTML-document to display same information. Now I have a problem displaying text that sometimes contains two kinds of quotes simultanelisly. I don't know on...
11
by: Ron | last post by:
Hello, I'm having an aggravating time getting the "html" spewed by Word 2003 to display correctly in a webpage. The situation here is that the people creating the documents only know Word, and...
2
by: Ed | last post by:
Hi, I'm stuck at the moment trying to work out how to access the value of a textfield which gets added in a DIV element. I have functions to add and remove the textfields from the elements as...
3
by: Jason | last post by:
I have several tables with quite a few fields and I'm getting errors when trying to insert records with single quotes in the data like: name = John O'Henry or a city name of O'Fallen So I went...
5
by: Dennis Fazekas | last post by:
Greetings, I am creating a web form which will all the user to add an unlimited number of email addresses. Basically I have 3 buttons, "Add Another Email", "-" to remove, and a "Save" button....
5
by: Hank Moss | last post by:
I've been able to get the <qelement and the CSS quotes property to work well together in English, but not in Russian or mixed Russian and English. I probably don't have a firm enough grasp of the...
6
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello, I have some XML that is returned to my application from another vendor that I cannot change before it gets to me. I can only alter it after it gets to my application. That being said, I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.