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

Space function expected array error

Status
Not open for further replies.

fenris

Programmer
May 20, 1999
824
CA
Here is an error that keeps cropping up. I have:

>code
>code

dim sBuffer as string
sBuffer = Space(1024)



This always errors out on me saying that it expected an array? Any Ideas.....




Troy Williams B.Eng.
fenris@hotmail.com

 
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 &quot;lz32.dll&quot; _
Alias &quot;GetExpandedNameA&quot; ( _
ByVal lpszSource As String, _
ByVal lpszBuffer As String) _
As Long
'=======================

Troy Williams B.Eng.
fenris@hotmail.com

 
fenris,

I tried the following code . . .


Dim sBuffer As String
sBuffer = Space$(1024)


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
(please note, that the page is under construction)
 
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
 
Rick, Thank you for the suggestion! It did the trick.

I used VBA.space.....


Thanks to everyone who helped and offered advice, Thanks.

Troy Williams B.Eng.
fenris@hotmail.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top