PDA

View Full Version : Can a function return an array?



martin
15-05-2009, 17:28
If yes, how....???

A small example code would be highly appreciated!

ErosOlmi
15-05-2009, 18:01
No, a function cannot return an array. It would be a really waste of memory.
But all arrays are passed BYREF to functions so whatever change you do on the array inside the function will effect the original array

See attached examples.

Eros

PS: in reality strings and direct memory access can be used to return a local function array to the external of the function but this would move a lot of memory and application would slow down a lot. But if you really need it I can show how.

martin
15-05-2009, 18:24
Hello Eros,

Thanks for your explanation and examples. They are easy to understand, I will try those demonstrated methods.

Have a good evening!

Martin

Lionheart008
15-05-2009, 18:42
hi martin, hi eros... :)

perhaps you can use also a little array example like this one ;)

it was an example I have made while my first experiences with arrays... and later followed the lotto script :)

@ martin, what for a script do you want to create ???


'-- little array example by lionheart 15.march.2009

uses "console", "UI"

randomize timer

dim myArrayNumbers(14) as long = 1
dim i,r as long

myArrayNumbers(1) = 10, 20, 30, 40, 50, 60,70,80,90,100,110,120, 130, 140

printl
Console_SetTextAttribute(Console_ForegroundRGB(1,1,1,1))
printl (" - Array example by lionheart, push a key to continue - ")
printl

FOR i = 1 to 10
myArrayNumbers(i) = i
NEXT i
waitkey
printl myArrayNumbers(i)
sleep 100

'-- shuffle kind...
FOR i = 1 TO 12
r = RND(1, 12)
SWAP myArrayNumbers(i), myArrayNumbers(r)
printl strformat$("{1}: {2} ", i, myArrayNumbers(i))
NEXT i

printl
waitkey
printl ("-- more to come with message box ---")
msgbox 0, "Hey array number..." + myArrayNumbers(i) + ,"", "GOOD I like arrays :) !"
printl
printl ("-- Push key to exit --")
waitkey
stop


have fun with it, ciao, Lionheart

martin
15-05-2009, 20:02
Hi Lionheart,

Thanks for your example. I am writing a freeware Mood player that can generate and play playlists based on genre, artist, tempo, year and other fields. I did this before in Visual Basic, but since I discovered ThinBasic I want to write it again from scratch as this language seems to be perfect to create such script. A unique thing will be that this player will be able to automaticly recognize music files by matching the filenames and id3tags with the database of Discogs.com.

What does your Lotto script exactly do?? $$$ :arms: $$$
Ciao ciao,
Martin

Petr Schreiber
15-05-2009, 20:10
Martin,

that sounds great, I will be looking forward to your software!

martin
17-05-2009, 10:28
Thanks Petr, I will post it on this forum when it's ready (or maybe earlier if I need some testing).

Lionheart008
24-05-2009, 21:41
shorty... @martin:)


What does your Lotto script exactly do?? $$$ Arms $$$

have a closer look at this board if you like ;)

http://community.thinbasic.com/index.php?topic=2484.msg20283;topicseen#new

more to come, I am sure, best wishes, Lionheart

ps: what about your progresses with thinbasic ??? ;)

martin
25-05-2009, 10:02
Hello Frank,

I already found your script last week but thanks anyway!
I'm learning and discover everyday new things about this great language. My Moodplayer script already has 600 lines now (only used for matching mp3's with discogs-database) :) I really like ThinBasic, it has everything I need , it's fast, easy to learn, smart keywords, and it runs under almost all windows-versions. Great great great!! :excited: