Returning arrays from function

fizbim
09-24-2002, 07:06 PM
How do I return a "Byte" type array from a function ? These bytes are byte size binary data 00-FF and may or may not be ASCII.

Here is my code.


***************************************************

Public Sub MySub()
Dim ByteArray() as Byte
Dim temp1 as byte
Dim temp2 as byte
Dim temp3 as byte

myByteArray = myFunctionCall(somevariable)

temp1 = ByteArray(0) ' should be 01
temp2 = ByteArray(1) ' should be 02
temp3 = ByteArray(2) ' should be 03

End Sub


Public Function myFunctionCall(ByVal DontCare) as Byte()
Dim TempArray() as Byte

TempArray(0) = 1
TempArray(1) = 2
TempArray(3) = 3

myFunctionCall = TempArray
End Function

****************************************************

fizbim
09-24-2002, 07:11 PM
Opps.

I found the answer.
Here is the correct calling procedure.

myByteArray() = myFunctionCall(somevariable)

-------- NOT ---------

myByteArray = myFunctionCall(somevariable)

fizbim
09-24-2002, 07:21 PM
I spoke too soon. This still doesn't work.

Gamer X
09-24-2002, 08:39 PM
Well, I'm not entirely sure what you're asking, but couldn't you skip the variable swapping processes(in MySub, and myFunctionCall) altogether? Ex:

Public Sub MySub()
Dim ByteArray() as Byte
Dim temp1 as byte
Dim temp2 as byte
Dim temp3 as byte

temp1 = myFunctionCall(0) ' should be 01
temp2 = myFunctionCall(1) ' should be 02
temp3 = myFunctionCall(2) ' should be 03

End Sub


Public Function myFunctionCall(ByVal DontCare) as Byte()
If DontCare = 0 then myFunctionCall(DontCare) = 1
If DontCare = 1 then myFunctionCall(DontCare) = 2
If DontCare = 2 then myFunctionCall(DontCare) = 3
'Or myFunctionCall(DontCare) = DontCare + 1
End Function

Hope that helps you somehow.

Arigato,
Gamer X

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum