Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Error - Expected Function or Varible

Posted on 1998-10-01
6
Medium Priority
?
175 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 120 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…
Suggested Courses

972 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