[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
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
Re: calling a function - compile error
tg,
ive publicly defined them in a module
They are populated in a different form.
Re: calling a function - compile error
Show us the code for both of those steps.
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
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)
Re: calling a function - compile error
Re: calling a function - compile error
scratch that...i made the changes in the wrong section...it worked.
Thanks very much! :)