Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Returning arrays from function


Reply
 
Thread Tools Display Modes
  #1  
Old 09-24-2002, 07:06 PM
fizbim fizbim is offline
Regular
 
Join Date: Feb 2001
Posts: 94
Default Returning arrays from function


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

****************************************************
Reply With Quote
  #2  
Old 09-24-2002, 07:11 PM
fizbim fizbim is offline
Regular
 
Join Date: Feb 2001
Posts: 94
Default

Opps.

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

myByteArray() = myFunctionCall(somevariable)

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

myByteArray = myFunctionCall(somevariable)
Reply With Quote
  #3  
Old 09-24-2002, 07:21 PM
fizbim fizbim is offline
Regular
 
Join Date: Feb 2001
Posts: 94
Default

I spoke too soon. This still doesn't work.
Reply With Quote
  #4  
Old 09-24-2002, 08:39 PM
Gamer X's Avatar
Gamer X Gamer X is offline
Senior Contributor
 
Join Date: Jul 2001
Location: /dev/meow
Posts: 1,180
Default Re: Returning arrays from function

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:
Code:
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
__________________
Webmaster, Senior Programmer, and all the rest at Gamer X Creations (currently offline)

Life would be much easier if I had the source code . . .
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->