Loading INI file details into Combobox

  • Thread starter Roderick O'Regan
  • Start date
R

Roderick O'Regan

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 protected]
phone=0155 456789
[Jones]
name=B Jones
[email protected]
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
 
A

Ali Bi

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
 
R

Roderick O'Regan

Thanks for the great help Jonathan and Ali (Norman). Time to try some
of this stuff out!

Regards

Roderick
 

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