|
-
May 22nd, 2001, 04:27 PM
#1
Megatron or other GURU error in Ini read
This is weird?
Code:
sSectionName = "Hello Newman"
sValueName = "Episode"
sIniDefault = "c:\wherever\seinfield.ini"
sIniFile = sIniDefault
Dim lReturnCheck As Long
Dim sReturnValue as String * 50
'
lReturnCheck = GetPrivateProfileString(sSectionName,sValueName,sIniDefault,sReturbValue,Len(sReturnValue),sIniFile)
'
If lReturnCheck = 0 Then
GetIniValue = ""
Else
GetIniValue = Trim(sReturnValue)
End If
Ok the problem is that even if the ini file does not exist lReturnCheck returns a value of 21 or 22 and sReturnValue has the ini File Name and 10 or so return characters.
How come lReturnCheck isn't returning 0?
-
May 22nd, 2001, 04:34 PM
#2
GetPrivateProfileString doesn't indicate by it's return value whether it has succeded in retriving the information from the file. It always return the length of the textbuffer, that is the lenght of the text retrieved.
And since you give a default value, it vil return the default value and the length of the returnvalue.
Thats it!!!!
A suggestion might be, to replace the default value with a empty string : "", that way you can detect the error be testing the returned string:
Code:
if strReturn = "" then debug.print "ERROR"
-
May 22nd, 2001, 04:40 PM
#3
It should be returning the number of characters in sIniDefault (this API is not one of those Success/Fail types).
-
May 22nd, 2001, 05:06 PM
#4
Hey thanks guys
That was quick, (as my wife is apt to say)
Good point AIS, will try that out...excellent works !!!!!!!!!!!!!!!!
Now all l have to do is figure out why on earth l had the "* 50" in the first place?
Our office net is down, am on site, so expect a heap of questions in the next few days...can never remember the API calls.
Megatron
Gorilla???????????????????????
-
May 22nd, 2001, 05:26 PM
#5
Guerrilla: It's another term for "Rebel"
-
May 22nd, 2001, 06:09 PM
#6
Originally posted by Megatron
Guerrilla: It's another term for "Rebel"
]
Now l get it. I was thinking in terms of the great Ape, not Che etc.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|