469,282 Members | 1,945 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

GetPrivateProfileString

I am trying to return a string from an .ini file, and keep getting the
following error:
"Arithmetic operation resulted in an overflow".

Has anyone seen this error before? What am I doing wrong?

Thanks!
Jul 21 '05 #1
3 2852
could you post the code you are using to get the ini value?

"kvrdeveloper1" wrote:
I am trying to return a string from an .ini file, and keep getting the
following error:
"Arithmetic operation resulted in an overflow".

Has anyone seen this error before? What am I doing wrong?

Thanks!

Jul 21 '05 #2
> could you post the code you are using to get the ini value?

The code that I am using is below. The values of the variables are as
follows: psSection: "LogOn", psEntry: "DBType", psDefault: "Microsoft SQL
Server", sReturnVal = Nothing, iBUFFER = 255, psFileName:
"C:\path\setting.ini"

Private Function gsGetProfileString(ByVal psSection As String, ByVal psEntry
As String, ByVal psDefault As String, ByVal psFileName As String) As String

Const iBUFFER As Integer = 255
Dim iLength As Integer
Dim sReturnVal As String

iLength = GetPrivateProfileString(psSection, psEntry, psDefault,
sReturnVal, iBUFFER, psFileName)

gsGetProfileString = Left(sReturnVal, iLength)

End Function

Jul 21 '05 #3
in your getprivateprofilestring function try changing the return value from a
sting to a stringbuilder.
when you call the function make sure to initialize the string builder to
your buffer size ie 255.
dim sReturnVal as System.Text.StringBuilder(250);
The string builder should marshel to an LPTSTR that's buffer can be writen to.
Aaron

"kvrdeveloper1" wrote:
could you post the code you are using to get the ini value?


The code that I am using is below. The values of the variables are as
follows: psSection: "LogOn", psEntry: "DBType", psDefault: "Microsoft SQL
Server", sReturnVal = Nothing, iBUFFER = 255, psFileName:
"C:\path\setting.ini"

Private Function gsGetProfileString(ByVal psSection As String, ByVal psEntry
As String, ByVal psDefault As String, ByVal psFileName As String) As String

Const iBUFFER As Integer = 255
Dim iLength As Integer
Dim sReturnVal As String

iLength = GetPrivateProfileString(psSection, psEntry, psDefault,
sReturnVal, iBUFFER, psFileName)

gsGetProfileString = Left(sReturnVal, iLength)

End Function

Jul 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by L | last post: by
1 post views Thread by Domac | last post: by
5 posts views Thread by 海风 | last post: by
2 posts views Thread by Nhan | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.