Results 1 to 8 of 8

Thread: [RESOLVED] calling a function - compile error

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2009
    Posts
    36

    Resolved [RESOLVED] calling a function - compile error

    Hi there,
    im having a problem with calling a sub procedure ive created. When i call it it says

    Compile error :
    Type mismatch: array or user-defined type expected

    il post the functions and then the call section.

    Code:
    Private Sub selection_sort_lott(ByRef lott_num(), ByRef lott_sort())
    Dim outer As Integer
    Dim inner As Integer
    Dim minimum As Integer
    Dim temp As Integer
    
    For outer = 1 To 3
        minimum = outer
        For inner = 1 To 3
            If lott_num(inner) <= lott_num(minimum) Then
                minimum = inner
            End If
        Next inner
        lott_sort(outer) = lott_num(minimum)
        lott_num(minimum) = " "
    Next outer
    End Sub
    Thats the function im trying to call. This is how im calling it. Im calling it in as the form loads.

    Code:
    Private Sub Form_Load()
    
    Call selection_sort_lott(lott_num(), lott_sort())
    Thanks for any help!

    p.s. if ive made a stupid nooby mistake, its cuz i am one!

    p.p.s lott_num is an integer

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: calling a function - compile error

    where are lott_num() and lott_sort() defined at? and where are you populating them?

    and it should be Call selection_sort_lott(lott_num, lott_sort) ... with out the () on the arrays.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2009
    Posts
    36

    Re: calling a function - compile error

    tg,

    ive publicly defined them in a module
    They are populated in a different form.

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: calling a function - compile error

    Show us the code for both of those steps.

  5. #5

    Thread Starter
    Member
    Join Date
    Dec 2009
    Posts
    36

    Re: calling a function - compile error

    heres the code

    populating array

    Code:
    'generates three random unique numbers
    Randomize
    Do
    lott_num(1) = Int((Rnd * 5) + 1)
    lott_num(2) = Int((Rnd * 5) + 1)
    lott_num(3) = Int((Rnd * 5) + 1)
    Loop While lott_num(1) = lott_num(2) Or lott_num(1) = lott_num(3) Or lott_num(2) = lott_num(3)
    dimming variables

    Code:
    Public lott_num(3) As Integer
    Public lott_sort(3) As Integer

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: calling a function - compile error

    It seems that it is actually a data type issue... your variables are Integer arrays, but the sub uses Variant arrays.

    Try these changes:
    Code:
    Private Sub selection_sort_lott(ByRef lott_num() As Integer, ByRef lott_sort() As Integer)

  7. #7

    Thread Starter
    Member
    Join Date
    Dec 2009
    Posts
    36

    Re: calling a function - compile error

    same thing happens...

  8. #8

    Thread Starter
    Member
    Join Date
    Dec 2009
    Posts
    36

    Re: calling a function - compile error

    scratch that...i made the changes in the wrong section...it worked.
    Thanks very much!

Posting Permissions

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



Click Here to Expand Forum to Full Width