Link to home
Start Free TrialLog in
Avatar of strongd
strongdFlag for United States of America

asked on

Error - Expected Function or Varible

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

Avatar of clifABB
clifABB

When you declare a variable as type class, make sure you use the New qualifier:

Example:
Dim DirectorySize As New Class1

Avatar of strongd

ASKER

Went ahead and did that ClifABB, but I am still getting the same error  "Expected function or varible", plus it higlights DirSize in code line         total = DirectorySize.DirSize(sPath, Dtotal).  Help?????
ASKER CERTIFIED SOLUTION
Avatar of clifABB
clifABB

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
By the way, you still need the 'New' qualifier.
Avatar of strongd

ASKER

Thanks ....
Avatar of strongd

ASKER

Thanks....