Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default "Config file"

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default "Config file"

Another option is to save the settings in a worksheet in the addin.

Remember that you'll want to save the workbook after you've made a change to the
settings (that you want to keep).

Or you could look at GetSetting and SaveSetting in VBA's help. These allow you
to retrieve and save settings from the windows registry.

Eric wrote:

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


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default "Config file"

Hi Eric,

i use a siple textfile and import it into the addin
like this:

Sub read_Txt()
Dim strfile As String
Dim strTxtrow As String

Open strfile For Input As #1
Do While Not EOF(1)
Line Input #1, strTxtrow
' row for row inoput
'Your code for......... whatever you need

Loop
Close #1
End Sub

hth
Nobby


"Eric" schrieb im Newsbeitrag
...
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




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default "Config file"

I would add to the other replies that you could/should save your settings
the System Registry instead of a text ini file. The registry was intended
and designed to replace the ini files of yesteryear. Using the registry has
the possible advantage that if there are two or more users of the same
machine, each with his own logon id, each user will have their own
configuration settings, rather than all users using the same config file,
with one user overwriting another user's settings.

For some simple code to work with the System Registry that wraps up all the
Windows APIs into nice, neat, VBA-friendly procedures, see
www.cpearson.com/excel/registry.htm .


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)


"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






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default "Config file"


"Chip Pearson" wrote in message
...
Using the registry has the possible advantage that if there are two or
more users of the same machine, each with his own logon id, each user will
have their own configuration settings, rather than all users using the
same config file, with one user overwriting another user's settings.


Easily overcome by adding the users login name to the filename or as part of
the key.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting "uppercase" string data to "lower case" in CSV file [email protected] Excel Discussion (Misc queries) 2 August 12th 08 08:36 PM
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
Lost "File Menu" - now it's "Edit / View / Insert.." but no "F daves Excel Discussion (Misc queries) 3 April 24th 07 04:52 AM
Problem- Recording macros for "file save" and "File open" tritaco Excel Programming 1 April 22nd 04 06:15 PM
"Headroom" on <Files=99 in config.sys Tim Childs Excel Programming 11 August 5th 03 11:23 PM


All times are GMT +1. The time now is 06:05 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"