Ask Your Question
0

LO BASIC : Passing array From Procedure to Function and Function returning array to Procedure

asked 2020-05-12 08:34:52 +0100

lonk gravatar image

updated 2020-05-12 08:35:38 +0100

Is it possible ?

Please help modify LO BASIC codes in attached file.C:\fakepath\PassArrayFromProcedureToFunctionAndFunctionReturnsArrayToProcedure.ods

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2020-05-12 13:28:57 +0100

Lupp gravatar image

updated 2020-05-12 13:53:44 +0100

The way arrays are handled results in getting them passed factually the ByRef way even if ByVal is expected or erxplicitly specified.
Your code contained lots of strange attempts due to misunderstandings. The tried BubbleSort contained an error.

Concerning the problem of passing arrays ByVal effectively I added a helper module from my toolbox previously published here. (Only parts of the module are actually used then.)
Concerning the mentioned misunderstandings and the BubbleSort error I made a reworked version from which you may learn. It is contained in this attachment:
C:\fakepath\ask243812guess_CcreateSortedArrayKeepingtheOriginal_1.ods.
If you are decisive to write "macros" in Basic, you should start at the beginning. Unfortunately I cannot point you to really good teaching texts. The famous texts by Andrew Pitonyak aren't exactly for beginners and are very much concerned about the usage of the uno API with Basic programming.

===Edit 2020-05-12 about 12:00UTC===
To avoid the need of using the mentioned toolbox you can, of course, use specialized code for making a copy of a simple one-dimensional array like:

l = Lbound(origArray) : u = Ubound(origArray)
Dim copiedArray(l To u)
For j = l To u
  copiedArray(j) = origArray(j)
Next j
edit flag offensive delete link more

Comments

Dear @Lupp,

Thank you so much for your assistance and your concern.

lonk gravatar imagelonk ( 2020-05-13 08:28:04 +0100 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2020-05-12 08:34:52 +0100

Seen: 64 times

Last updated: May 12 '20