Solved

Error - Expected Function or Varible

Posted on 1998-10-01
6
169 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
  • 3
  • 3
6 Comments
 
LVL 6

Expert Comment

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

Example:
Dim DirectorySize As New Class1

0
 

Author Comment

by:strongd
ID: 1437669
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?????
0
 
LVL 6

Accepted Solution

by:
clifABB earned 30 total points
ID: 1437670
Silly me, I should have loaded your code the first time.

You have DirSize as a Sub:
Public Sub DirSize(spath As String, dtotal As Double)

It should be a function:
Public Function DirSize(spath As String, dtotal As Double)

Also the click event has some bad code:
      total = DirectorySize.DirSize(spath, dtotal)
       
      Text1.Text = DirectorySize

Should probably read:
      dtotal = DirectorySize.DirSize(spath, dtotal)
       
      Text1.Text = dtotal
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 6

Expert Comment

by:clifABB
ID: 1437671
By the way, you still need the 'New' qualifier.
0
 

Author Comment

by:strongd
ID: 1437672
Thanks ....
0
 

Author Comment

by:strongd
ID: 1437673
Thanks....
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

772 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