[EO] Count Files

This is my first Tutorial,

I tell you, how to can count the files in the orders and display on your server form.

Before we beginn, we need following things:
1x Modul (modCounts)
1x Frame (Directory File Count)
1x Label (Accounts)

Let’s begin:
You create a Modul and you give it the name modFileCounts

And add the follow Code in the Modul:

Function CountAccounts() As Long
Dim d As String
Dim i As Long

d = Dir("data\accounts\*.*")

Do Until d = ""
    i = i + 1
    d = Dir
Loop
frmServer.lblCountAccounts.Caption = "Accounts: " & i
End Function

Next, you create the Frame and the Lable

Like this:

Now you give the new Label the name lblCountAccounts.

Next you search in the frmServer for

Private Sub Form_Load()
    Call UsersOnline_Start
End Sub

Below you add this:

Private Sub Form_Activate()
    Call CountAccounts
End Sub

And in the End it look like this:

And what do this?
It counts the files in the Folder of Accounts ;D

When you would to count the maps you must add this in the modFileCounts

Below the CountAccounts Function:

Function CountMaps() As Long
Dim d As String
Dim i As Long

d = Dir("data\maps\*.*")

Do Until d = ""
    i = i + 1
    d = Dir
Loop
frmServer.lblCountMaps.Caption = "Maps: " & i
End Function

Now a new Label in the Directory File Count Frame:

The name of the Lable is lblCountMaps

At last you search for Call CountAccounts and below you add this Call CountMaps

In the end it look like this:

PS: I’m new in VB6

Pls delete the second post, sry

@Ryujin:

Pls delete the second post, sry

There is an edit button for that.

Anyway, very nice tutorial, but why would you make a whole module for one sub?

@Erwin:

There is an edit button for that.

Anyway, very nice tutorial, but why would you make a whole module for one sub?

Flexibility maybe.

@Erwin:

Anyway, very nice tutorial, but why would you make a whole module for one sub?

Well, you could you make that module for counting all the directory’s, etc for organization.

Log in to reply