?
Solved

filling an array with filenames

Posted on 2003-02-22
1
Medium Priority
?
275 Views
Last Modified: 2013-11-13
hi how do u fill a dynamic array with file names, i have this code but it fills a listbox, how do i modify this to fill an array.

And pass that array over a winsock control i.e send data.







Sub ScanDir(ByVal vsPath As String, lstList As ListBox)

'=========================================================
'Purpose    Populate a given listbox with the names of all
'           files in a given directory.
'Entry      vsPath - full pathname of the directory to
'           search.
'           lstList - the list box to populate
'Exit       None, but contents of list box will have been
'           modified.
'Comments   One of Marks routines!

Dim sNextEntry As String
Dim iLen As Integer
Dim iAttr As Integer

'Constants for use with GetAttr():
Const ATTR_NORMAL = 0       'Normal file
Const ATTR_READONLY = 1     'Read-only file
Const ATTR_HIDDEN = 2       'Hidden file
Const ATTR_SYSTEM = 4       'System file
Const ATTR_VOLUME = 8       'Volume label
Const ATTR_DIRECTORY = 16   'MS-DOS directory
Const ATTR_ARCHIVE = 32     'File has changed since last back-up

'Define types of files etc to search for
iAttr = ATTR_NORMAL + ATTR_READONLY + ATTR_HIDDEN + ATTR_SYSTEM

'Make sure path is terminated with a \ character
iLen = Len(vsPath)
If iLen > 0 And Mid$(vsPath, iLen, 1) <> "\" Then vsPath = vsPath & "\"

'Get first entry in directory, initialises Dir()
sNextEntry = Dir(vsPath, iAttr)

'Now fetch all other entries
While Len(sNextEntry)

    'Only include 'reasonable' filenames
    If sNextEntry <> "." And sNextEntry <> ".." Then
        lstList.AddItem sNextEntry
    End If

    'Fetch next filename
    sNextEntry = Dir
Wend

End Sub

0
Comment
Question by:RazaHasnain
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 80 total points
ID: 8001888
dim idx as integer
dim ffiles() as string
'Now fetch all other entries
While Len(sNextEntry)

   'Only include 'reasonable' filenames
   If sNextEntry <> "." And sNextEntry <> ".." Then
       redim preserve ffiles(idx)
       ffiles(idx)= sNextEntry
       idx=idx+1
   End If

   'Fetch next filename
   sNextEntry = Dir
Wend

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question