Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2007

Tip: Looking for answers? Try searching our database.

INI Files - Multiple Lines

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Martin Cameron - 16 Nov 2007 04:38 GMT
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.
Graham Mayor - 16 Nov 2007 07:20 GMT
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

Signature

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Can anyone tell me if it is possible to enter multiple lines into an
> INI file.
[quoted text clipped - 14 lines]
> returned.
> I suspect that I will have to programatically enter VBCrLf.
Graham Mayor - 16 Nov 2007 08:11 GMT
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)

Signature

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> 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:
[quoted text clipped - 28 lines]
>> returned.
>> I suspect that I will have to programatically enter VBCrLf.
Summer - 16 Nov 2007 08:54 GMT
Graham does it matter if one has more than 3 lines - sometimes an address is
6 lines?

> Or even simpler, as the lack of the found comma will not produce an error
>
[quoted text clipped - 34 lines]
>>> returned.
>>> I suspect that I will have to programatically enter VBCrLf.
Graham Mayor - 16 Nov 2007 11:38 GMT
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 = "gmayor@REMOVETHISmvps.org"

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

Signature

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Graham does it matter if one has more than 3 lines - sometimes an
> address is 6 lines?
[quoted text clipped - 43 lines]
>>>> Street is returned.
>>>> I suspect that I will have to programatically enter VBCrLf.
Karl E. Peterson - 16 Nov 2007 18:44 GMT
> Can anyone tell me if it is possible to enter multiple lines into an INI file.
>
[quoted text clipped - 12 lines]
> 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 ", ".
Signature

.NET: It's About Trust!
http://vfred.mvps.org

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.