Thread: "Config file"
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips Bob Phillips is offline
external usenet poster
 
Posts: 10,593
Default "Config file"

You could use an INI file.

Private Declare Function GetPrivateProfileInt Lib "kernel32" _
Alias "GetPrivateProfileIntA" _
(ByVal lpApplicationName As String, _
ByVal lpKeyName As String, _
ByVal nDefault As Long, _
ByVal lpFileName As String) As Long

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

and use like so

cSubItems = GetPrivateProfileInt("myApp", "Id", 0, Filename)

and

Dim sKeyValue As String
Dim nLen As Long

sKeyValue = Space$(255)
nLen = GetPrivateProfileString(AppId, "myApp", "Id", "Not Found", _
sKeyValue, Len(sKeyValue), Filename)
If nLen = Len(sKeyValue) - 1 Then
'means sKeyValue not long enough
sKeyValue = Space$(Len(sKeyValue) + 100)
Else
sKeyValue = Left(sKeyValue, nLen)
End If



--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Eric" wrote in message
...
Hi,

I am writing an add-in and one of its first duty should be to be able to
read a "config file" containing several settings necessary to the other
procedures in the add-in.
Another procedure in the add-in will also allow the user to change and
save
new settings into this same config file.

I really don't know where to start? How would you go about it?

Thank you.


Eric