Solved

Grid and File list

Posted on 2000-04-07
3
217 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

809 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