Solved

Grid and File list

Posted on 2000-04-07
3
213 Views
Last Modified: 2010-05-02
I need to populate a grid with a list of files in one directory. How do i go about it?
0
Comment
Question by:eliasis
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
wsh2 earned 100 total points
ID: 2693311
1. Open a New Standard.Exe Project
2. Add a FlexGrid to the form (MSFlexGrid1).
3. Set a reference (Vb Menu -> Project -> Reference) to the "Microsoft Scripting Runtime" (SCRRUN.DLL).
4. Copy and paste the following into your Form1 code window.
5. Change the Directory name to what ever you like.

<----- Code Begin ----->

Private Sub Form_Load()

  xFolderList ("c:\Windows") <---- CHANGE

End Sub

Private Sub xFolderList _
(ByVal strDirectory As String) _

  Dim fsoWork As FileSystemObject
  Dim fsoFolder As Folder
  Dim fsoFile As File
 
  Set fsoWork = CreateObject("Scripting.FileSystemObject")
  Set fsoFolder = fsoWork.GetFolder(strDirectory)
 
  MSFlexGrid1.Clear
  MSFlexGrid1.Cols = 5
  MSFlexGrid1.Rows = 0
  MSFlexGrid1.AddItem ( _
    "Line" & vbTab & _
    "Name" & vbTab & _
    "DateCreated" & vbTab & _
    "DateLastAccessed" & vbTab & _
    "DateLastModified" & vbTab)
 
  Dim intLine As Integer
  For Each fsoFile In fsoFolder.Files
    MSFlexGrid1.AddItem ( _
      intLine & vbTab & _
      fsoFile.Name & vbTab & _
      fsoFile.DateCreated & vbTab & _
      fsoFile.DateLastAccessed & vbTab & _
      fsoFile.DateLastModified & vbTab)
  Next fsoFile
 
  MSFlexGrid1.FixedRows = 1

End Sub

<----- Code End ----->
0
 

Author Comment

by:eliasis
ID: 2693431
wsh2, thank you
just to understand it better what is "Microsoft Scripting Runtime" (SCRRUN.DLL) being used for?
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2693568
Setting the reference, provides the SCRRUN.DLL interfaces so that you can use the File System Object class programming contained inside of it. In essence, rather than programming all the nuts and bolts of File System Access, you are hooking into a Microsoft program library that provides that functionality, and then using the methods and properties there to achieve what you want.. <smile>.

The main difference between a Component and a Reference is that a Component usually requires a form / graphical interface while a reference does not. As such.. FSO (SCRRUN.DLL) is just like a Microsoft Control, only it does not require a Graphical User interface.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
DIR issue 7 50
Excel object stays open 19 70
Excel VBA, find a string in a column, update a cell 7 65
How to make an ADE file by code? 11 79
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now