+ Reply to Thread
Results 1 to 4 of 4

Duplicate Declaration in Current Scope

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-24-2010
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2003
    Posts
    195

    Talking Duplicate Declaration in Current Scope

    Hi folks,

    I'm trying to add a True/False Boolean to a Check File Exists script that I've been useing.
    Basically if the Boolean is True I'm checking the existance of 2 files, otherwise just the one.

    I've been playing about trying to set up an If statement within the script but the cycles seem to be causing problems.

    With the below code I'm getting Compile Error; Duplicate Declaration in Current Scope.
    Any suggestions on the best way to get around this?

    I want to try avoid having the If statement call a seperate Sub.


    Sub CheckFilesExistDPD60(Send60Monthly)
    
    
    If Send60Monthly = True Then
    Dim filepaths(100) As Variant
    
            filepaths(1) = DPD60NAMA
            filepaths(2) = DPD60NAMA
     'Loop
    For I = 1 To 2 'Or filepaths(i) = ""
        If Len(Dir(filepaths(I))) > 0 Then
            Else: MsgBox ("file not found" & filepaths(I))
            End
            Exit For
        End If
    Next I
    
    Else
    Dim filepaths(100) As Variant          <------Compile Error Here
    
            filepaths(1) = DPD60NAMA
     'Loop
    For I = 1 To 1 'Or filepaths(i) = ""
        If Len(Dir(filepaths(I))) > 0 Then
            Else: MsgBox ("file not found" & filepaths(I))
            End
            Exit For
        End If
    Next I
    
    
    End If
    
    End Sub
    Last edited by TonyforVBA; 11-23-2011 at 08:24 AM.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,298

    Re: Duplicate Declaration in Current Scope

    Why are you declaring the same variable twice? Remove the second declaration, or use a different variable.
    Remember what the dormouse said
    Feed your head

  3. #3
    Forum Contributor
    Join Date
    02-07-2011
    Location
    netherlands
    MS-Off Ver
    Excel 2003
    Posts
    128

    Re: Duplicate Declaration in Current Scope

    Dim filepaths(100) As Variant          <------Compile Error Here
    Remove the line you can only Dim 1 time for a variable within a subject



    also:
    Dim filepaths(100) As Variant
    
            filepaths(1) = DPD60NAMA
            filepaths(2) = DPD60NAMA
    this doesnt make much sence except making it harder for your self:
    declaring a multi array if u both set the same value?

    Remove the (100)/ (1)/ (2)/ (I) and u got the same result.

  4. #4
    Forum Contributor
    Join Date
    02-24-2010
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2003
    Posts
    195

    Re: Duplicate Declaration in Current Scope

    Haha, I dont know what I was at there. I think I need another cup of coffee.
    Cheers
    Tony

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1