Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Overflow Error

Status
Not open for further replies.

BaDi

Programmer
May 14, 2002
32
0
0
NL
Hi!

When I start my application, the application reads a few string values from a .ini file into variables. But when the first variable is set and the application wants to fill the next one it says: runtime error 6: "overflow"

I can't find the cause of this. Can anybody help?

Thanx in advance!
 

--------------------------------------------

Code:

Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As Any, ByVal lpFileName As String) As Long

Declare Function WritePrivateProfileSection Lib "kernel32" Alias "WritePrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpString As String, ByVal lpFileName As String) As Long

Declare Function GetPrivateProfileSection Lib "kernel32" Alias "GetPrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

Public Function ReadWriteINI(Mode As String, tmpSecname As String, tmpKeyname As String, Optional tmpKeyValue) As String

On Error GoTo ReadWriteINIError

Dim AppPath As String
Dim tmpString As String
Dim FileName As String
Dim secname As String
Dim keyname As String
Dim KeyValue As String
Dim anInt
Dim defaultkey As String

AppPath = App.Path

' ******* TEST FOR GOOD DATA TO WORK WITH ****************
If IsNull(Mode) Or Len(Mode) = 0 Then

ReadWriteINI = "ERROR MODE" ' Set the return value
Exit Function

End If

If IsNull(tmpSecname) Or Len(tmpSecname) = 0 Then

ReadWriteINI = "ERROR Secname" ' Set the return value
Exit Function

End If

If IsNull(tmpKeyname) Or Len(tmpKeyname) = 0 Then

ReadWriteINI = "ERROR Keyname" ' Set the return value
Exit Function

End If

' ******* SET THE INI FILENAME ***************************
FileName = AppPath & "\IniFile.ini"

' ******* WRITE MODE *************************************
If UCase(Mode) = "WRITE" Then

If IsNull(tmpKeyValue) Or Len(tmpKeyValue) = 0 Then

ReadWriteINI = "ERROR KeyValue"
Exit Function

Else

secname = tmpSecname
keyname = tmpKeyname
KeyValue = tmpKeyValue

anInt = WritePrivateProfileString(secname, keyname, KeyValue, FileName)

End If

End If


' ******* READ MODE **************************************
If UCase(Mode) = "GET" Then

secname = tmpSecname
keyname = tmpKeyname
defaultkey = "Failed"
KeyValue = String$(50, 32)
anInt = GetPrivateProfileString(secname, keyname, defaultkey, KeyValue, Len(KeyValue), FileName)

If Left(KeyValue, 6) <> &quot;Failed&quot; Then ' *** got it

tmpString = KeyValue
tmpString = RTrim(tmpString)
tmpString = Left(tmpString, Len(tmpString) - 1)

End If

ReadWriteINI = tmpString

End If

Exit Function

ReadWriteINIError:
MsgBox Error
Stop

End Function

Public Sub Initialise_local_variables()

LocalVar1 = App.Path & ReadWriteINI(&quot;GET&quot;, &quot;SECTION_A&quot;, &quot;key_a&quot;)

LocalVar2 = App.Path & ReadWriteINI(&quot;GET&quot;, &quot;SECTION_B&quot;, &quot;key_b&quot;)

End sub

--------------------------------------------

The local variables are declared in a module.
When I want to fill LocalVar2 the application gives the overflow-error.

--------------------------------------------

this is the ini-file:

[SECTION_A]
key_a = &quot;Test1&quot;
Key_b = &quot;Test2&quot;

--------------------------------------------

Any help is welcome!

Thanx in advance!
 
My guess is that the overflow error is being caused by the call to GetPrivateProfileString. That funtion returns a long, and the result is being (or trying to be) stored in the variable anInt.

First thing I would do is change

Dim anInt to
Dim anInt as Long
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
tried your code and did not get an overflow error

can you post the declaration of the following variables?

[tt]Dim/Public/Private LocalVar1 As ???
Dim/Public/Private LocalVar2 As ???[/tt]

I also note that you did not post the contents of SECTION_B of your .ini file

[tt]LocalVar2 = App.Path & ReadWriteINI(&quot;GET&quot;, &quot;SECTION_B&quot;, &quot;key_b&quot;)[/tt]
 
Public LocalVar1 As String
Public LocalVar2 As String

about the SECTION_B thing : This had to be SECTION_A. Type-mistake.

Thanx for you help! I hope you can find the cause!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top