?
Solved

Error - Expected Function or Varible

Posted on 1998-10-01
4
Medium Priority
?
155 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 80 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

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!

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

765 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