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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding reference causes failure to function... 1

Status
Not open for further replies.

kalle82

Technical User
Apr 2, 2009
163
SE
Hi!

A problem I never expected has occured... :(

I am using excel 2003. In my application i create .ini files and read them on occasion.

Now Im trying to connect my application via API to another program. In order to access that programs api I added that programs reference library. BUT this is when my problems started.

The function i use to read my .ini files stopped working.

It has to do with the row second from the bottom. The word left is somehow causing it to crash. My error message is: "Wrong number of arguments or invalid property definition".

Once i remove the reference problem disappears?

How should I go by to solve this?


Code:
GetPrivateProfileString32 = Left(strReturnString, lngValid)

Code:
Function GetPrivateProfileString32(ByVal strFileName As String, _
    ByVal strSection As String, ByVal strKey As String, _
    Optional strDefault) As String
Dim strReturnString As String, lngSize As Long, lngValid As Long
    On Error Resume Next
    If IsMissing(strDefault) Then strDefault = ""
    strReturnString = Space(1024)
    lngSize = Len(strReturnString)
    lngValid = GetPrivateProfileStringA(strSection, strKey, _
        strDefault, strReturnString, lngSize, strFileName)
    GetPrivateProfileString32 = Left(strReturnString, lngValid)
    On Error GoTo 0
End Function
 
Does the problem occur with the Left function, or in assigning the result of the Left function to the GetPrivateProfileString32 function return value?

If you are not sure, you could assign the Left() output to a dummy string on one line then assign that string to the main function return value on the next line. Then see which of those two lines causes the error.
 
Hi! N1ghteyes!

I assigned the left function to a dummy string. See below.

Same problem I get an error for having wrong number of arguments or invalid property definitions..

Code:
Dim arne As String
   arne = "12233232123223"
   
   lefstring = Left(Space(1024), arne)
            
   MsgBox (leftstring)

 
So it does occur with the left function....
 
The second argument for the Left function should be a long. It looks like you are supplying a string instead. Read the help on Left().

Tony
 
Hey! I just beat the problem. The other type library also had a left function. So what I Did was the following.
VBA.STRING.LEFT()

And that solved my problem. Forcing it to Use the correct LEFT.
 


In the VB Editor Tools > Refrences you can MOVE the references UP or DOWN using the controls. Visual Basic for Applications ought to be moved to the FIRST position.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I didn't know that! Thanks for the tip Skip.

I'm still puzzling over why the OP's Left() function ever worked when supplying the 2nd argument as a string instead of a long.

Tony
 
Late answer, but I checked my references window and VBA was on the top and the other type library was at the far bottom of my included references. I also thougt there would be som innate priority order.

But anways it's now working and I learned that you can by pressing F2 check all functions and directly access them the long way in case of having two with the same name ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top