Home All Groups Group Topic Archive Search About

Writing to simple text file, get rid of quotes

Author
1 Aug 2005 5:17 PM
Brian Wojo
When I write to a simple text file to create an ".INI" type file, I've
noticed that VB automatically encloses everything with quotes (the variable
types I am using are strings).  For example, an ".INI" file looks like:
[SECTION HEADING]
data1 = "string"

When I use the Write command using a simple sequential file I attempt to
write string variables to the file.  For example my code looks like:
Dim data as String
Open path for Output As #1
data = "[SECTION HEADING]"
Write #1, data

The problem is that all of the strings I output to the file are
automatically enclosed in quotes, so the result of the sample code above
write the text file like:

"[SECTION HEADING]"

Does anyone know how to output a string variable to a simple text file
WITHOUT having the strings enclosed in quotes?

Author
1 Aug 2005 5:24 PM
Saga
Instead of write, use:

print #handle, data


Also, if you are explicitly manipulating anINI file, these APIs help:

Private Declare Function GetPrivateProfileString Lib "kernel32" Alias
"GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal
lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As
String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias
"WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal
lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As
Long


Note: If you place these in a BAS module, use Public instead of private.

Good luck!
Saga


Show quoteHide quote
"Brian Wojo" <BrianW***@discussions.microsoft.com> wrote in message
news:25CC832D-801A-479D-948B-8C3EB9A5925B@microsoft.com...
> When I write to a simple text file to create an ".INI" type file, I've
> noticed that VB automatically encloses everything with quotes (the
> variable
> types I am using are strings).  For example, an ".INI" file looks
> like:
> [SECTION HEADING]
> data1 = "string"
>
> When I use the Write command using a simple sequential file I attempt
> to
> write string variables to the file.  For example my code looks like:
> Dim data as String
> Open path for Output As #1
> data = "[SECTION HEADING]"
> Write #1, data
>
> The problem is that all of the strings I output to the file are
> automatically enclosed in quotes, so the result of the sample code
> above
> write the text file like:
>
> "[SECTION HEADING]"
>
> Does anyone know how to output a string variable to a simple text file
> WITHOUT having the strings enclosed in quotes?
Author
1 Aug 2005 5:27 PM
Tim Rude
Stop using Write # and start using Print # instead.

The VB help for the Write statement mentions: "Unlike the Print # statement,
the Write # statement inserts commas between items and quotation marks
around strings as they are written to the file."

The 'See Also' link points to the Print # statement.

--
Tim Rude

timrude@NOSPAM.hotmail.com
(remove NOSPAM. for correct email address)

Show quoteHide quote
"Brian Wojo" <BrianW***@discussions.microsoft.com> wrote in message
news:25CC832D-801A-479D-948B-8C3EB9A5925B@microsoft.com...
> When I write to a simple text file to create an ".INI" type file, I've
> noticed that VB automatically encloses everything with quotes (the
variable
> types I am using are strings).  For example, an ".INI" file looks like:
> [SECTION HEADING]
> data1 = "string"
>
> When I use the Write command using a simple sequential file I attempt to
> write string variables to the file.  For example my code looks like:
> Dim data as String
> Open path for Output As #1
> data = "[SECTION HEADING]"
> Write #1, data
>
> The problem is that all of the strings I output to the file are
> automatically enclosed in quotes, so the result of the sample code above
> write the text file like:
>
> "[SECTION HEADING]"
>
> Does anyone know how to output a string variable to a simple text file
> WITHOUT having the strings enclosed in quotes?