Problems with reading / writing ini-file

Y

Youp

Hi,

I have an Excel workbook that uses an ini-file.

The principle I'm using is as follows:
There is a basic sheet that is used to create calculations. The user always
opens the basis sheet when creating new calculations. When opening this file,
it is checked whether a certain ini-file is present. If not the data for this
file has to be entered first (via a form that is called from the sheet). Some
things that are stored in this ini-file are the file location for storing the
calculations and a sequence number that is used for creating file-names for
the calculation.

When the user is ready with his calculation, the user presses a button in
the sheet. This will do the following: a unique name for the calculation is
created (using the seq. number from the ini-file); the calculation is save
using this name; the sequence number in the ini-file is increased).

For reading / writing the ini-file I use:
- getWindowsDirectory for determining the Windows directory
- WritePrivateProfileString/GetPrivateProfileString for writing and reading
the ini-file.

For quite some time this has worked without any problems. On most systems I
have it still works (i.e. XP Home SP2 with Excel 2003 SP2; XP Pro SP2 with
Excel 2000 SP3). However a user has a laptop (XP Pro SP2 + Excel 2003 SP2)
where these functions do not work!!
The function getWindowsDirectory returns no result and the functions
WritePrivateProfileString and GetPrivataProfileString do not work correctly.

Does anyone know (the cause of) this problem?
How could I solve this issue?

I'm looking for some general solution that will work on all the different
environments.

Thanx in advance
Youp
 
B

Bob Phillips

Does your code look like

Dim sDir As String
Dim cLength As Long

sDir = Space(255)
cLength = GetSystemDirectory(sDir, 255)
sDir = Left(sDir, cLength)
Debug.Print "System directory path: "; sDir


--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)
 
Y

Youp

Hi,

This is the code that I currently use:

lngx = apiGetWindowsDirectory(strIniFile, Len(strIniFile))
If lngx <> 0 Then
GetIniFileName = Left(strIniFile, lngx) & "\" & "PTPT.ini"
Else
GetIniFileName = Empty
End If

So the principle is the same as in your example.

Youp
 
B

Bob Phillips

What about apiGetWindowsDirectory?

--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)
 
Y

Youp

It's declared as follows:

Private Declare Function apiGetWindowsDirectory& Lib "kernel32" Alias
"GetWindowsDirectoryA" _
(ByVal lpbuffer As String, ByVal nSize As Long)

I tried the function you're mentioning on my XP Pro / Excel 2000 environment
(which is working fine with the above function) and this results in an error
(Microsoft Excel for Windows has encountered a problem and needs to close...).

Youp
 

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