+ Reply to Thread
Results 1 to 3 of 3

type mismatch

Hybrid View

  1. #1
    Registered User
    Join Date
    12-23-2008
    Location
    USA
    Posts
    60

    type mismatch

    I delcare an array of dates and assign it with a function that returns an array of dates. Then I want to pass the result to a sub which takes an array of dates as a parameter. However, I am getting a type mismatch error on this line

        SetStartDate (WorkingDates)
    Here is the smallest version of the error producing code.

    Sub Button1_Click()
        Dim DateArray() As Date
        WorkingDates = GetWorkingDateList()
        
        SetStartDate (WorkingDates)
    End Sub
    
    Function GetWorkingDateList() As Date()
        Dim DateList(2) As Date
        DateList(1) = Date
        GetWorkingDateList = DateList
    End Function
    
    Sub SetStartDate(DateList() As Date)
        MsgBox DateList(1)
    End Sub
    What have I done wrong?

    Thanks!

    Dave
    Last edited by daviddoria; 12-27-2008 at 10:02 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Declare your variables, and Excel is fussy about the syntax of calling subs.
    Sub x()
        Dim WorkingDates() As Date
        
        WorkingDates = GetWorkingDateList()
        
        ' You can do this
        SetStartDate WorkingDates
        ' ... or this:
        Call SetStartDate(WorkingDates)
        ' ... but not this:
        ' SetStartDate (WorkingDates)
    End Sub
    
    Function GetWorkingDateList() As Date()
        Dim DateList(2) As Date
        DateList(1) = Date
        GetWorkingDateList = DateList
    End Function
    
    Sub SetStartDate(DateList() As Date)
        MsgBox DateList(1)
    End Sub
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    12-23-2008
    Location
    USA
    Posts
    60
    Ah perfect - what bizarre syntax!

+ 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