473,326 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

How to return 2d Array from a Function?

My code:
Expand|Select|Wrap|Line Numbers
  1. Public Function PNL(Model As String, Station As String) As Variant
  2.     Dim tbl As DAO.Recordset
  3.     Dim BodyFrom As Double
  4.     Dim BodyTo As Double
  5.     Dim i As Double
  6.     Dim Box As String, PNum As String, MaxLot As Long
  7.     Dim BFZ()
  8.  
  9.     Set tbl = CurrentDb.OpenRecordset("_0_Thong_Tin_Ve_Box")
  10.     tbl.MoveFirst
  11.     had_Box = False
  12.     i = 1
  13.     Do Until tbl.EOF
  14.         If tbl!ModelType = Model And tbl!Matram = Station Then
  15.             Box = tbl!Box
  16.             PNum = tbl!partnumber
  17.             MaxLot = tbl!MaxLot
  18.             ReDim BFZ(1 To i, 1 To 3)
  19.             BFZ(i, 1) = PNum
  20.             BFZ(i, 2) = Box
  21.             BFZ(i, 3) = MaxLot
  22.  
  23.             PNL = BFZ()
  24.             had_Box = True
  25.             Debug.Print BFZ(i, 2)
  26.             i = i + 1
  27.  
  28.         End If
  29.         tbl.MoveNext
  30.     Loop
  31.     If had_Box = True Then Exit Function
  32.     ReDim BFZ(1 To 1, 1 To 3)
  33.     BFZ(1, 1) = "Empty"
  34.     BFZ(1, 2) = ""
  35.     BFZ(1, 3) = ""
  36.     PNL = BFZ()
  37. End Function
  38.  
  39.  
I call it and show result but it empty although it have data
Expand|Select|Wrap|Line Numbers
  1.  PNLf = PNL(Model, MaStation_tx) ' Get PNum, Box va MaxLot
  2.                     u1 = UBound(PNLf, 1)
  3.                    box = PNLf(1, 2)
  4.                     Debug.Print box
Please help me, many thanks
Dec 13 '19 #1
2 1527
cactusdata
214 Expert 128KB
You can't use ReDim this way. Study the documentation:
ReDim Statement

You can use the GetRows method of a recordset to retrieve the records' field values in an array.
Dec 14 '19 #2
I will try
Thanks cactusdata
Dec 14 '19 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: BrianP | last post by:
Hi, I have had to invent a work-around to get past what looks like a JavaScript bug, the malfunctioning Perl-like JavaScript array functions including SPLICE() and UNSHIFT(). I have boiled it...
0
by: Marc van Boven | last post by:
I'm stuck with the following problem: My nusoap-client calls a server-function giveCombination(). The function giveCombination should return something like array( => array( 'a_id' => 6,...
16
by: priya | last post by:
Hi all, I am new to this group.I am working in c language.I have dount in pointer? how to retun array of pointer in function? example main()
2
by: kathy | last post by:
how to return array from function?
2
by: Ali | last post by:
hi i need to send some data to the function and want to return array of object bac lik dim obj() as myclass=AddIt(i,j i dont know that is write syntax or no public function addit(byval i as...
0
by: DWalker | last post by:
VBA, as used in Excel 2000 and Excel 2003, has a function called Array. It's commonly seen in statements like the following: Workbooks.OpenText Filename:=ACFileName, _ StartRow:=1,...
26
by: MLH | last post by:
How would I modify the following to achieve a 2-dimensional array? Dim MyWeek, MyDay MyWeek = Array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun") ' Return values assume lower bound set to 1...
10
by: Raj | last post by:
I need a VB function to return array of collections like Private Type Employee empname as string address as string salary as integer deptno as integer End Type dim employees() as Employee
9
by: =?Utf-8?B?RGFya21hbg==?= | last post by:
Hi, I am wondering how you multi-dimension an array function? My declared function looks like this: Public Function GetCustomerList(ByVal Val1 As String, ByVal Val2 As Long, ByVal Val3 As...
0
by: Muzamil | last post by:
What I'm making mistake I want to display in such a way Enter the number : 4 Factorial of 4 is : 1x2x3x4 = 24! using System; using System.Collections.Generic; using System.Linq; using...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.