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

subscript out of range

Status
Not open for further replies.

warren2600

Programmer
Jun 28, 2004
13
0
0
US
Can someone take a look at my code.
i'm working on several different projects and my brain hurts.
Private Sub Command1_Click()

Dim fso As New FileSystemObject
Dim f As Folder, sf As Folder, path As String
Dim server As String
Dim i As Integer
Dim FileArray() As String


server = combServers.Text
'get rid of spaces for UNC path
server = RTrim(Left(server, InStrRev(server, " "))) & _
LTrim(RTrim(Right(server, Len(server) - InStrRev(server, " "))))

'Initialize path.
path = ("folder path")

'Get a reference to the Folder object.
Set f = fso.GetFolder(path)


For Each sf In f.SubFolders

'this is where the error occurs "subscript out of range"

------------> FileArray(i) = path <------------
i = i + 1
Next


'send array to function to calculate size
portalSize1 (FileArray)


End Sub




any input would help
thanks in advance,
warren

 
Hi Warren,

You have not given any dimensions to your FileArray array.

You need to either give it a size as you declare it i.e.
Dim FileArray(10) As String

or

ReDim as you go along
i.e.
For Each sf In f.SubFolders

ReDim Preserve FileArray(i) ' ReDim array here and preserve contents
FileArray(i) = path
i = i + 1
Next

Dave
 
You've got to set a size for FileArray somewhere. Maybe say:

Redim FileArray(f.SubFolders.Count - 1)

before you start trying to load it with values.
 

warren2600,

It appears that this part:

' 'get rid of spaces for UNC path
server = RTrim(Left(server, InStrRev(server, " "))) & _
LTrim(RTrim(Right(server, Len(server) - InStrRev(server, " "))))


does not work all the time. Try "f f" and try "f f f" for server.

vladk
 
Try this

server = Replace(server, " ", vbNullString)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top