INI Files - Multiple Lines

M

Martin Cameron

Can anyone tell me if it is possible to enter multiple lines into an INI file.

I have a form that is filled in with fields for name, address, phone. The
address is multiple lines. When the submit button is clicked, I want the INI
file to be written as follows

[Contact Details]
Name=Joe Bloggs
Address=10 Any Street,
Smithson
New Zealand
Phone=+64783921002

Unfortunately, When the data is read back, only the line with the key is
returned - in this case for the address, only 10 Any Street is returned.
I suspect that I will have to programatically enter VBCrLf.
 
G

Graham Mayor

I don't think this is possible. Instead, why not insert the address as a
single line with the lines separated by a comma and a space thus:

10 Any Street, Smithson, New Zealand

then you can read that as separate lines with (say)

Dim lBreak As String

lBreak = "," & vbCr
If InStr(1, Address, ", ") <> 0 Then
Address = replace(Address, ", ", lBreak)
End If


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Graham Mayor

Or even simpler, as the lack of the found comma will not produce an error

Dim lBreak As String
lBreak = "," & vbCr
Address = replace(Address, ", ", lBreak)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Graham said:
I don't think this is possible. Instead, why not insert the address
as a single line with the lines separated by a comma and a space thus:

10 Any Street, Smithson, New Zealand

then you can read that as separate lines with (say)

Dim lBreak As String

lBreak = "," & vbCr
If InStr(1, Address, ", ") <> 0 Then
Address = replace(Address, ", ", lBreak)
End If



Martin said:
Can anyone tell me if it is possible to enter multiple lines into an
INI file.

I have a form that is filled in with fields for name, address, phone.
The address is multiple lines. When the submit button is clicked, I
want the INI file to be written as follows

[Contact Details]
Name=Joe Bloggs
Address=10 Any Street,
Smithson
New Zealand
Phone=+64783921002

Unfortunately, When the data is read back, only the line with the key
is returned - in this case for the address, only 10 Any Street is
returned.
I suspect that I will have to programatically enter VBCrLf.
 
S

Summer

Graham does it matter if one has more than 3 lines - sometimes an address is
6 lines?

Graham Mayor said:
Or even simpler, as the lack of the found comma will not produce an error

Dim lBreak As String
lBreak = "," & vbCr
Address = replace(Address, ", ", lBreak)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Graham said:
I don't think this is possible. Instead, why not insert the address
as a single line with the lines separated by a comma and a space thus:

10 Any Street, Smithson, New Zealand

then you can read that as separate lines with (say)

Dim lBreak As String

lBreak = "," & vbCr
If InStr(1, Address, ", ") <> 0 Then
Address = replace(Address, ", ", lBreak)
End If



Martin said:
Can anyone tell me if it is possible to enter multiple lines into an
INI file.

I have a form that is filled in with fields for name, address, phone.
The address is multiple lines. When the submit button is clicked, I
want the INI file to be written as follows

[Contact Details]
Name=Joe Bloggs
Address=10 Any Street,
Smithson
New Zealand
Phone=+64783921002

Unfortunately, When the data is read back, only the line with the key
is returned - in this case for the address, only 10 Any Street is
returned.
I suspect that I will have to programatically enter VBCrLf.
 
G

Graham Mayor

It shouldn't make any difference how many lines as long as the required
separate address lines are each separated by a comma and a space. - up to a
character limit of around 250. The address is read as the one line that it
is, and the additional code

lBreak = "," & vbCr
Address = replace(Address, ", ", lBreak)

break the string into a series of paragraphs which can be entered as a
block.

I use something similar to the following to read from Settings.ini stored in
the Word startup folder which contains a section something like

[UserName]
Name = "Graham Mayor"
Address = "1 My Street, My Town, My PostCode, My Country"
Phone = "99 123456"
Email = "(e-mail address removed)"


Sub AddDataFromINIFile()
Dim SettingsFile As String
Dim Name As String
Dim Address As String
Dim EMail As String
Dim Phone As String
Dim lBreak As String

SettingsFile = Options.DefaultFilePath(wdStartupPath) & "\Settings.ini"

Name = System.PrivateProfileString(SettingsFile, _
"UserName", "Name")
Address = System.PrivateProfileString(SettingsFile, _
"UserName", "Address")

lBreak = "," & vbCr
Address = replace(Address, ", ", lBreak)

Phone = System.PrivateProfileString(SettingsFile, _
"UserName", "Phone")
EMail = System.PrivateProfileString(SettingsFile, _
"UserName", "Email")

With Selection
.TypeText Text:=Name
.TypeParagraph
.TypeText Text:=Address
.TypeParagraph
.TypeParagraph
.TypeText Text:="Phone: " & Phone
.TypeParagraph
.TypeText Text:="E-mail: " & EMail
End With
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham does it matter if one has more than 3 lines - sometimes an
address is 6 lines?

Graham Mayor said:
Or even simpler, as the lack of the found comma will not produce an
error Dim lBreak As String
lBreak = "," & vbCr
Address = replace(Address, ", ", lBreak)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Graham said:
I don't think this is possible. Instead, why not insert the address
as a single line with the lines separated by a comma and a space
thus: 10 Any Street, Smithson, New Zealand

then you can read that as separate lines with (say)

Dim lBreak As String

lBreak = "," & vbCr
If InStr(1, Address, ", ") <> 0 Then
Address = replace(Address, ", ", lBreak)
End If



Martin Cameron wrote:
Can anyone tell me if it is possible to enter multiple lines into
an INI file.

I have a form that is filled in with fields for name, address,
phone. The address is multiple lines. When the submit button is
clicked, I want the INI file to be written as follows

[Contact Details]
Name=Joe Bloggs
Address=10 Any Street,
Smithson
New Zealand
Phone=+64783921002

Unfortunately, When the data is read back, only the line with the
key is returned - in this case for the address, only 10 Any
Street is returned.
I suspect that I will have to programatically enter VBCrLf.
 
K

Karl E. Peterson

Martin said:
Can anyone tell me if it is possible to enter multiple lines into an INI file.

I have a form that is filled in with fields for name, address, phone. The
address is multiple lines. When the submit button is clicked, I want the INI
file to be written as follows

[Contact Details]
Name=Joe Bloggs
Address=10 Any Street,
Smithson
New Zealand
Phone=+64783921002

Unfortunately, When the data is read back, only the line with the key is
returned - in this case for the address, only 10 Any Street is returned.
I suspect that I will have to programatically enter VBCrLf.

I'll second Graham's advice, but suggest that you use a character-sequence that is
somewhat less likely to actually appear in your dataset. For example, maybe use the
HTML "<br>" line break sequence, rather than ", ".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top