Solved

Error - Expected Function or Varible

Posted on 1998-10-01
4
145 Views
Last Modified: 2010-04-30
I am trying to get an object to work.  It goes out and gets the directory size.  Here the code it have so far.  Someone Please help me.   This is my first object I have created, I have no idea what the problem is...Thanks

Public spath As Class1
Public dtotal As Class1

Private Sub CmdGetSize_Click()
      Dim DirectorySize As Class1
      Dim spath As String
     
      Dim dtotal As Double
     
      dtotal = 0
      spath = Text1.Text
      dtotal = 0
     
      dtotal = 0
      total = DirectorySize.DirSize(spath, dtotal)
     
      Text1.Text = DirectorySize
     
     
End Sub

Here is Model1 code

Public dtotal As Double
Public spath As String


Here is Class1 code

Public spath As String
Public dtotal As Double

Public Sub DirSize(spath As String, dtotal As Double)
       

       Dim sDir          As String
       Dim colDir        As New Collection
       Dim nI            As Integer
       Dim dLocalTotal   As Double

       If Right(spath, 1) <> "\" Then spath = spath & "\"
       
       dLocalTotal = 0
       
       ' *** Get all the files
       sDir = Dir(spath & "*.*", vbArchive + vbDirectory + vbHidden + vbNormal + vbReadOnly + vbSystem)
       Do While sDir <> ""
          ' *** If it is a directory, ignore it
          If (GetAttr(spath & sDir) And vbDirectory) <> vbDirectory Then
             dLocalTotal = dLocalTotal + FileLen(spath + sDir)
          Else
             If (Left(sDir, 1) <> ".") Then colDir.Add sDir
          End If
          sDir = Dir()   ' *** Get next entry
       Loop

       ' *** Get all the directorie
       For nI = 1 To colDir.Count
          Call DirSize(spath & colDir(nI), dLocalTotal)
       Next
       
       Set colDir = Nothing
       
       dtotal = dtotal + dLocalTotal
       
       DirSize = dLocalTotal

    End Sub

0
Comment
Question by:strongd
  • 2
4 Comments
 
LVL 6

Expert Comment

by:clifABB
Comment Utility
This is a duplicate question.

You should delete it.
0
 
LVL 2

Accepted Solution

by:
schild earned 20 total points
Comment Utility
You have two problem over here
a major and a minor one

The major is:
Insted of lines:
Public spath As Class1
Public dtotal As Class1

you must put those:
Public spath As New Class1
Public dtotal As New Class1
This will sole you the run time error that you got.
The "New" for a object instance in needed, exaclly as you doen with "Collection" object.

The minor problem is that ambiguase declaration of variables:
Public spath As String
Public dtotal As Double
Public Sub DirSize(spath As String, dtotal As Double)

The result is that inside "DirSize" subrutine, the function recognize only the local variable and not the globals.

Good luck with your first Object
0
 
LVL 6

Expert Comment

by:clifABB
Comment Utility
schild:
You are incorrect.
By using a public variable in a form, it becomes a property of that form.  This removes the ambiguity.

Also, as I noted in the answer to the question that this is a duplicate of, the problem is that DirSize is declared as a sub and should be declared as a function.

strongd:
As this is a duplicate question, you should consider deleting it and save yourself some points.
0
 

Author Comment

by:strongd
Comment Utility
Thanks.....It is working finally......
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

771 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

14 Experts available now in Live!

Get 1:1 Help Now