The code you gave works fine for me. What error indication are you getting (exact message, what line is the yellow highlighting on)? Could you have Dim'ed sBuffer as another type earlier in the code? Rick Sprague
Are you sure you didn't redefine Space as a Public function (accepting arrays) or as a Property somewhere in your project?
By the way: It doesn't hurt to use Space$ as, by definition, characters will be returned to a String variable. _________________________________
In theory, there is no difference between theory and practice. In practice, there is. [attributed to Yogi Berra]
I tried using the Space$() but that did not help. I also thought about the redefining of the function, but I can not find any reference to it.
The problem stems from this. I have a project that I created a while back to access the windows API (see below). In a new project that I am creating I require the use of this function, So I copied and pasted it into the project and now VB thinks Space(1024) is an array. But it works fine in my old project!
'=====================
Public Function fileExpandedName( _
ByVal sFilename As String) _
As String
Dim sBuffer As String
sBuffer = Space(1024) '<<<<<<<<<<Errors out here with a message, Expected Array
GetExpandedName sFilename, sBuffer
fileExpandedName = sNT(sBuffer)
End Function
Public Function sNT( _
ByVal sString As String) _
As String
Dim iNullLoc As Integer
iNullLoc = InStr(sString, Chr(0))
If iNullLoc > 0 Then
sNT = Left(sString, iNullLoc - 1)
Else
sNT = sString
End If
End Function
'========================
'API
Public Declare Function GetExpandedName _
Lib "lz32.dll" _
Alias "GetExpandedNameA" ( _
ByVal lpszSource As String, _
ByVal lpszBuffer As String) _
As Long
'=======================
and I've have not been able to reproduce your error . . . by the way, rvBasic is correct in suggesting that you add a $ to then end of all string functions. This will force them to return string variables and not variants and this will increase your performance. But back to your problem . . .
as I said, I was not able to recreate your error, but I would make this suggestion . . . make sure that you have Option Explicit added to all of your modules/classes/forms. I mention this just in case VB for some reason thinks the Space(1024) command (perhaps with some kind of hidden control character in it - yeah I know, its a stretch) is an implicitly declared array variable. Beyond that, I don't know why your code is failing on the Space command.
- Jeff Marler
The Space function is the the VBA library. Check your References, and make sure you don't have another library with a Space function at a higher priority in the list. Alternatively, try using VBA.Space(1024). Rick Sprague
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.