+ Reply to Thread
Results 1 to 5 of 5

Type Mismatch: array or user defined type expected

  1. #1
    ExcelMonkey
    Guest

    Type Mismatch: array or user defined type expected

    I have an array that I am trying to sort. I keep getting an this compile
    error:
    "Type Mismatch: array or user defined type expected "
    on the line Call Sort(NumberOfRuns - 1, EBITDAArray). It highlights the
    EBITDAArray.

    Why is this? Thanks

    Sub Main ()
    Dim EBITDAArray as Variant
    Dim X as Double
    Dim NumberOfRuns as Double

    For X = NumberOfRuns - 1
    'Populate Array with code
    Next

    Call Sort(NumberOfRuns - 1, EBITDAArray)
    End Sub

    Sub Sort(n As Double, arr() As Variant)

    Dim Temp As Double
    Dim i As Long
    Dim j As Long

    For j = 2 To n
    Temp = arr(j)
    For i = j - 1 To 1 Step -1
    If (arr(i) <= Temp) Then GoTo 10
    arr(i + 1) = arr(i)
    Next i
    i = 0
    10 arr(i + 1) = Temp
    Next j

    End Sub

  2. #2
    Tom Ogilvy
    Guest

    RE: Type Mismatch: array or user defined type expected

    EBITDAArray isn't a variant array - it is a variant that contains an array.
    So change the declaration in the sort Sub.

    Sub Main()
    Dim EBITDAArray As Variant
    Dim X As Double
    Dim NumberOfRuns As Double
    NumberOfRuns = 20
    ReDim EBITDAArray(1 To NumberOfRuns - 1)
    For X = 1 To NumberOfRuns - 1
    EBITDAArray(X) = Int(Rnd() * 1000 + 1)
    'Populate Array with code
    Next

    Call Sort(NumberOfRuns - 1, EBITDAArray)
    For X = 1 To NumberOfRuns - 1
    Debug.Print EBITDAArray(X)
    Next
    End Sub

    Sub Sort(n As Double, arr As Variant)

    Dim Temp As Double
    Dim i As Long
    Dim j As Long

    For j = 2 To n
    Temp = arr(j)
    For i = j - 1 To 1 Step -1
    If (arr(i) <= Temp) Then GoTo 10
    arr(i + 1) = arr(i)
    Next i
    i = 0
    10 arr(i + 1) = Temp
    Next j

    End Sub

    --
    Regards,
    Tom Ogilvy


    "ExcelMonkey" wrote:

    > I have an array that I am trying to sort. I keep getting an this compile
    > error:
    > "Type Mismatch: array or user defined type expected "
    > on the line Call Sort(NumberOfRuns - 1, EBITDAArray). It highlights the
    > EBITDAArray.
    >
    > Why is this? Thanks
    >
    > Sub Main ()
    > Dim EBITDAArray as Variant
    > Dim X as Double
    > Dim NumberOfRuns as Double
    >
    > For X = NumberOfRuns - 1
    > 'Populate Array with code
    > Next
    >
    > Call Sort(NumberOfRuns - 1, EBITDAArray)
    > End Sub
    >
    > Sub Sort(n As Double, arr() As Variant)
    >
    > Dim Temp As Double
    > Dim i As Long
    > Dim j As Long
    >
    > For j = 2 To n
    > Temp = arr(j)
    > For i = j - 1 To 1 Step -1
    > If (arr(i) <= Temp) Then GoTo 10
    > arr(i + 1) = arr(i)
    > Next i
    > i = 0
    > 10 arr(i + 1) = Temp
    > Next j
    >
    > End Sub


  3. #3
    markwalling
    Guest

    Re: Type Mismatch: array or user defined type expected

    please include your polulate code. my guess is thats where the problem
    is

    ExcelMonkey wrote:
    > I have an array that I am trying to sort. I keep getting an this compile
    > error:
    > "Type Mismatch: array or user defined type expected "
    > on the line Call Sort(NumberOfRuns - 1, EBITDAArray). It highlights the
    > EBITDAArray.
    >
    > Why is this? Thanks
    >
    > Sub Main ()
    > Dim EBITDAArray as Variant
    > Dim X as Double
    > Dim NumberOfRuns as Double
    >
    > For X = NumberOfRuns - 1
    > 'Populate Array with code
    > Next
    >
    > Call Sort(NumberOfRuns - 1, EBITDAArray)
    > End Sub
    >
    > Sub Sort(n As Double, arr() As Variant)
    >
    > Dim Temp As Double
    > Dim i As Long
    > Dim j As Long
    >
    > For j = 2 To n
    > Temp = arr(j)
    > For i = j - 1 To 1 Step -1
    > If (arr(i) <= Temp) Then GoTo 10
    > arr(i + 1) = arr(i)
    > Next i
    > i = 0
    > 10 arr(i + 1) = Temp
    > Next j
    >
    > End Sub



  4. #4
    ExcelMonkey
    Guest

    RE: Type Mismatch: array or user defined type expected

    Thansk Tom. Just realised the sort sub is was used assuming Option Base 1.
    If I am using Option Base 0 then I am assuming I have to adjust certain items
    in the sub. Which ones need adjsuting? Is j = 1?

    > Sub Sort(n As Double, arr As Variant)
    >
    > Dim Temp As Double
    > Dim i As Long
    > Dim j As Long
    >
    > For j = 2 To n
    > Temp = arr(j)
    > For i = j - 1 To 1 Step -1
    > If (arr(i) <= Temp) Then GoTo 10
    > arr(i + 1) = arr(i)
    > Next i
    > i = 0
    > 10 arr(i + 1) = Temp
    > Next j
    >
    > End Sub


    "Tom Ogilvy" wrote:

    > EBITDAArray isn't a variant array - it is a variant that contains an array.
    > So change the declaration in the sort Sub.
    >
    > Sub Main()
    > Dim EBITDAArray As Variant
    > Dim X As Double
    > Dim NumberOfRuns As Double
    > NumberOfRuns = 20
    > ReDim EBITDAArray(1 To NumberOfRuns - 1)
    > For X = 1 To NumberOfRuns - 1
    > EBITDAArray(X) = Int(Rnd() * 1000 + 1)
    > 'Populate Array with code
    > Next
    >
    > Call Sort(NumberOfRuns - 1, EBITDAArray)
    > For X = 1 To NumberOfRuns - 1
    > Debug.Print EBITDAArray(X)
    > Next
    > End Sub
    >
    > Sub Sort(n As Double, arr As Variant)
    >
    > Dim Temp As Double
    > Dim i As Long
    > Dim j As Long
    >
    > For j = 2 To n
    > Temp = arr(j)
    > For i = j - 1 To 1 Step -1
    > If (arr(i) <= Temp) Then GoTo 10
    > arr(i + 1) = arr(i)
    > Next i
    > i = 0
    > 10 arr(i + 1) = Temp
    > Next j
    >
    > End Sub
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    > "ExcelMonkey" wrote:
    >
    > > I have an array that I am trying to sort. I keep getting an this compile
    > > error:
    > > "Type Mismatch: array or user defined type expected "
    > > on the line Call Sort(NumberOfRuns - 1, EBITDAArray). It highlights the
    > > EBITDAArray.
    > >
    > > Why is this? Thanks
    > >
    > > Sub Main ()
    > > Dim EBITDAArray as Variant
    > > Dim X as Double
    > > Dim NumberOfRuns as Double
    > >
    > > For X = NumberOfRuns - 1
    > > 'Populate Array with code
    > > Next
    > >
    > > Call Sort(NumberOfRuns - 1, EBITDAArray)
    > > End Sub
    > >
    > > Sub Sort(n As Double, arr() As Variant)
    > >
    > > Dim Temp As Double
    > > Dim i As Long
    > > Dim j As Long
    > >
    > > For j = 2 To n
    > > Temp = arr(j)
    > > For i = j - 1 To 1 Step -1
    > > If (arr(i) <= Temp) Then GoTo 10
    > > arr(i + 1) = arr(i)
    > > Next i
    > > i = 0
    > > 10 arr(i + 1) = Temp
    > > Next j
    > >
    > > End Sub


  5. #5
    Tom Ogilvy
    Guest

    RE: Type Mismatch: array or user defined type expected

    this would be my guess:

    Sub Main()
    Dim EBITDAArray As Variant
    Dim X As Double
    Dim NumberOfRuns As Double
    NumberOfRuns = 5
    ReDim EBITDAArray(NumberOfRuns)
    For X = LBound(EBITDAArray) To NumberOfRuns
    EBITDAArray(X) = Int(Rnd() * 1000 + 1)
    'Populate Array with code
    Next

    Call Sort(NumberOfRuns, EBITDAArray)
    For X = LBound(EBITDAArray) To NumberOfRuns
    Debug.Print X, EBITDAArray(X)
    Next
    End Sub

    Sub Sort(n As Double, arr As Variant)

    Dim Temp As Double
    Dim i As Long
    Dim j As Long

    For j = LBound(arr) + 1 To n
    Temp = arr(j)
    For i = j - 1 To LBound(arr) Step -1
    If (arr(i) <= Temp) Then GoTo 10
    arr(i + 1) = arr(i)
    Next i
    i = LBound(arr) - 1
    10 arr(i + 1) = Temp
    Next j

    End Sub

    --
    Regards,
    Tom Ogilvy


    "ExcelMonkey" wrote:

    > Thansk Tom. Just realised the sort sub is was used assuming Option Base 1.
    > If I am using Option Base 0 then I am assuming I have to adjust certain items
    > in the sub. Which ones need adjsuting? Is j = 1?
    >
    > > Sub Sort(n As Double, arr As Variant)
    > >
    > > Dim Temp As Double
    > > Dim i As Long
    > > Dim j As Long
    > >
    > > For j = 2 To n
    > > Temp = arr(j)
    > > For i = j - 1 To 1 Step -1
    > > If (arr(i) <= Temp) Then GoTo 10
    > > arr(i + 1) = arr(i)
    > > Next i
    > > i = 0
    > > 10 arr(i + 1) = Temp
    > > Next j
    > >
    > > End Sub

    >
    > "Tom Ogilvy" wrote:
    >
    > > EBITDAArray isn't a variant array - it is a variant that contains an array.
    > > So change the declaration in the sort Sub.
    > >
    > > Sub Main()
    > > Dim EBITDAArray As Variant
    > > Dim X As Double
    > > Dim NumberOfRuns As Double
    > > NumberOfRuns = 20
    > > ReDim EBITDAArray(1 To NumberOfRuns - 1)
    > > For X = 1 To NumberOfRuns - 1
    > > EBITDAArray(X) = Int(Rnd() * 1000 + 1)
    > > 'Populate Array with code
    > > Next
    > >
    > > Call Sort(NumberOfRuns - 1, EBITDAArray)
    > > For X = 1 To NumberOfRuns - 1
    > > Debug.Print EBITDAArray(X)
    > > Next
    > > End Sub
    > >
    > > Sub Sort(n As Double, arr As Variant)
    > >
    > > Dim Temp As Double
    > > Dim i As Long
    > > Dim j As Long
    > >
    > > For j = 2 To n
    > > Temp = arr(j)
    > > For i = j - 1 To 1 Step -1
    > > If (arr(i) <= Temp) Then GoTo 10
    > > arr(i + 1) = arr(i)
    > > Next i
    > > i = 0
    > > 10 arr(i + 1) = Temp
    > > Next j
    > >
    > > End Sub
    > >
    > > --
    > > Regards,
    > > Tom Ogilvy
    > >
    > >
    > > "ExcelMonkey" wrote:
    > >
    > > > I have an array that I am trying to sort. I keep getting an this compile
    > > > error:
    > > > "Type Mismatch: array or user defined type expected "
    > > > on the line Call Sort(NumberOfRuns - 1, EBITDAArray). It highlights the
    > > > EBITDAArray.
    > > >
    > > > Why is this? Thanks
    > > >
    > > > Sub Main ()
    > > > Dim EBITDAArray as Variant
    > > > Dim X as Double
    > > > Dim NumberOfRuns as Double
    > > >
    > > > For X = NumberOfRuns - 1
    > > > 'Populate Array with code
    > > > Next
    > > >
    > > > Call Sort(NumberOfRuns - 1, EBITDAArray)
    > > > End Sub
    > > >
    > > > Sub Sort(n As Double, arr() As Variant)
    > > >
    > > > Dim Temp As Double
    > > > Dim i As Long
    > > > Dim j As Long
    > > >
    > > > For j = 2 To n
    > > > Temp = arr(j)
    > > > For i = j - 1 To 1 Step -1
    > > > If (arr(i) <= Temp) Then GoTo 10
    > > > arr(i + 1) = arr(i)
    > > > Next i
    > > > i = 0
    > > > 10 arr(i + 1) = Temp
    > > > Next j
    > > >
    > > > End Sub


+ 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