Solved

Error - Expected Function or Varible

Posted on 1998-10-01
4
150 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
ID: 1437685
This is a duplicate question.

You should delete it.
0
 
LVL 2

Accepted Solution

by:
schild earned 20 total points
ID: 1437686
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
ID: 1437687
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
ID: 1437688
Thanks.....It is working finally......
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…

808 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