Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HOW DO I RETURN AN ARRAY FROM A FUNCTION PROCEDURE 1

Status
Not open for further replies.

TNN

Programmer
Sep 13, 2000
417
0
0
US
I am trying to return an array from a called function. I think this is something new in VB6 but I can't make it work.
Any help is appreciated.
I have tried the following code with no success:

Public Function EvaluateHrs(B As Integer, i As Integer) As Currency()
Dim EvaluateHrsItems(2) As Currency
'Calculations here.
EvaluateHrsItems(0) = Calc1
EvaluateHrsItems(1) = Calc2
EvaluateHrsItems(2) = Calc3
EvaluateHrs = EvaluateHrsItems
End Function

'Calling function from this Sub.
Public Sub CalcGross(B as integer, i As Integer)
Dim HrsItems() As Currency
HrsItems()=EvaluateHrs B, i 'This line won't work
If HrsItems(0) <> 0 Then
curOTPay = HrsItems(0)
End If

'etc.
End Sub

Thank You for any help.
TNN, Tom
TNPAYROLL@AOL.COM



TOM
 
Here's how:
Excuse the extra code, I was just checking. When talking to the array you see it as a pointer and so exclude the brackets:

Option Explicit

Private Sub Form_Load()
CalcGross 3, 1
End Sub
Public Function EvaluateHrs(B As Integer, i As Integer) As Currency()
Dim EvaluateHrsItems(2) As Currency
'Calculations here.
EvaluateHrsItems(0) = 10
EvaluateHrsItems(1) = 20
EvaluateHrsItems(2) = 30
EvaluateHrs = EvaluateHrsItems
End Function

'Calling function from this Sub.
Public Sub CalcGross(B As Integer, i As Integer)
Dim HrsItems() As Currency, curOTPay As Currency
HrsItems = EvaluateHrs(B, i) 'Now it should
If HrsItems(0) <> 0 Then
curOTPay = HrsItems(0)
End If

'etc.
End Sub


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top