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 / March 2005

Tip: Looking for answers? Try searching our database.

Loading INI file details into Combobox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Roderick O'Regan - 01 Mar 2005 14:52 GMT
I have a userform in a Word 2002 template with a combobox populated by
hard coding the various list  items within the procedure.

Now I would like to do this automatically from an INI file. The
structure of this INI file is as follows:
[Smith]
name=A Smith
email=a.smith@ISP.com
phone=0155 456789
[Jones]
name=B Jones
email=barryjones@ISP.com
phone=0432 765432

...and so on.

What I was thinking about is whether there is a routine which looks at
all of the section names and can load these into a combo box (without
the brackets, of course)?

Based on the choice in the combo box I can then use the
System.PrivateProfileString to extract the relevant details from the
appropriate keyname such as email, phone, etc.

Could anyone point me in the direction where I can read up/download
such a procedure, please?

Regards

Roderick O'Regan
Jonathan West - 01 Mar 2005 21:19 GMT
Hi Roderick

Karl Peterson has a recently-updated INI-file class on his website, which
should do all you need. Go to
http://vb.mvps.org/samples/project.asp?id=kpini

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

>I have a userform in a Word 2002 template with a combobox populated by
> hard coding the various list  items within the procedure.
[quoted text clipped - 26 lines]
>
> Roderick O'Regan
Ali Bi - 01 Mar 2005 21:20 GMT
>What I was thinking about is whether there is a routine which looks at
>all of the section names and can load these into a combo box (without
>the brackets, of course)?
>
>Roderick O'Regan

Dear Roderick
heres some long unused code

Public Declare Function GetAllProfileString Lib "kernel32" Alias
"GetPrivateProfileStringA" (ByVal lpApplicationName As Any, ByVal
lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString
As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

'? split(getSections(),vbnullchar)(0) => Jones
'? split(getSections(),vbnullchar)(1) => Smith

Public Function getSections()
   On Local Error GoTo getSectionsERR
   Dim strRet As String
   Dim lngRet As Long
   strRet = String(255, 0)
'Ini is the Name of the containing Document/Template in this Example
   ini = Left$(ThisDocument.FullName, Len(ThisDocument.FullName) - 3)
& "ini"
   lngRet = GetAllProfileString(vbNullString, "", "", strRet,
Len(strRet), ini)
   If lngRet Then
       getSections = Left$(strRet, lngRet)
   End If
getSectionsOUT:
   Exit Function
getSectionsERR:
   getSections = False
   Resume getSectionsOUT
End Function

hth
Ali Bi
Norman Götz
Roderick O'Regan - 02 Mar 2005 08:53 GMT
Thanks for the great help Jonathan and Ali (Norman). Time to try some
of this stuff out!

Regards

Roderick

>>What I was thinking about is whether there is a routine which looks at
>>all of the section names and can load these into a combo box (without
[quoted text clipped - 36 lines]
>Ali Bi
>Norman Götz
 
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.