Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
With version 0.5, Small Basic implements native support for arrays. This is a significant change from how arrays were used in v0.4 and so I want to write about the syntax and the functionality of the new arrays.
Any variable can be used as an array – no special declaration or setup is necessary. Arrays are indexed using square brackets.
numbers[1] = "One"
numbers[2] = "Two"
TextWindow.WriteLine(numbers[1])
TextWindow.WriteLine(numbers[2])
Arrays can be indexed with either numbers or text. And you can use different types of indexers in the same array.
myarray["one"] = 1
myarray[2300] = "Two thousand three hundred"
myarray["name"] = "Vijaye"
Arrays can be copied over via simple assignment. Modifying one array doesn’t affect the other array.
first[1] = "Uno"
first[2] = "Dos"
second = first
TextWindow.WriteLine(second[2]) ' prints Dos
second[1] = "One"
TextWindow.WriteLine(second[1]) ' prints One
TextWindow.WriteLine(first[1]) ' prints Uno
The values in an array are internally maintained as a string with semicolon separated values:
person["Name"] = "Vijaye"
person["Age"] = 30
person["Address"] = "Redmond"
TextWindow.WriteLine(person)
This prints:
Name=Vijaye;Age=30;Address=Redmond;
You can remove elements in an array by setting them to an empty text.
myarray[1] = "One"
myarray[2] = "Two"
myarray[3] = "Three"
TextWindow.WriteLine(Array.GetItemCount(myarray)) ' prints 3
myarray[2] = ""
TextWindow.WriteLine(Array.GetItemCount(myarray)) ' prints 2
And finally, arrays can be multi-dimensional too
people[1]["Name"]["First"] = "Vijaye"
people[1]["Name"]["Last"] = "Raji"
people[2]["Name"]["First"] = "Carl"
people[2]["Name"]["Last"] = "Fredrickson"
TextWindow.WriteLine(people[2]["Name"])
This prints:
First=Carl;Last=Fredrickson;
Theoretically, you can have as many dimensions as you want. However, the way they are implemented internally, a two dimensional array is 2 times slower than a single dimension array, and a three dimensional array is 4 times slower than a single dimensional array and so on. So, I’d recommend not overdoing multidimensional arrays.
Comments
Anonymous
June 20, 2009
PingBack from http://www.alvinashcraft.com/2009/06/20/dew-drop-weekend-edition-june-20-21-2009/Anonymous
June 20, 2009
Thank you for submitting this cool story - Trackback from DotNetShoutoutAnonymous
June 20, 2009
Thank you for submitting this cool story - Trackback from progg.ruAnonymous
July 04, 2009
Dear Small Basic Blog, Thank you for "Arrays in Small Basic", it's very helpful considering that documentation and examples are sparce! A document similiar to "Introducing Small Basic" (pdf) on "Data Structures and Algorithms in Small Basic" would be Perfect!! Also, how about "Design Patterns in Small Basic?" Would Microsoft's article on data structures in C# help here? Yes, I think so! Thanks again! Flight!Anonymous
August 02, 2009
I would like to second Mr. "Flight Computer" from Sunday, July 5, 2009 2:15 AM! It is a shot in the dark after going through the "introducing small Basic" pdf file as to where to go next for furthr instruction to learn and share. What next...? Overall, great starting program, just want to develop more not stop due to lack of further instruction etc.. Thanks.Anonymous
August 16, 2009
I have read "introducing small Basic". Is there any other related materials for learning small basic in a whole system? Thanks.Anonymous
August 27, 2009
'DKZ463 '************ Miskei Vendel '************ www.miskei.hu '************ 2009 GraphicsWindow.Title="Winter" GraphicsWindow.Width=640 GraphicsWindow.Height=480 pic = Flickr.GetRandomPicture("Winter") GraphicsWindow.DrawResizedImage(pic, 0, 0, 640, 480) GraphicsWindow.DrawBoundText(530,460,110,"www.miskei.hu") gw =640 gh =480 For i=1 To 50 ho=i/6+1 GraphicsWindow.BrushColor = "#ffffff" GraphicsWindow.PenColor="#ffffff" ball[i] = Shapes.AddEllipse(ho, ho) x[i] = Math.GetRandomNumber(600)+20 y[i] = Math.GetRandomNumber(460)+10 EndFor RunLoop: For i=1 To 50 dX[i] = 2Math.GetRandomNumber(2)-2 dY[i] = 2Math.GetRandomNumber(2) If i<20 Then dy[i]=dy[i]-2 EndIf x[i] = x[i] + dX[i] y[i] = y[i] + dY[i] If y[i]>=gh Then y[i] = -20 x[i] = Math.GetRandomNumber(600)+20 EndIf Shapes.Move(ball[i], x[i], y[i]) EndFor Goto RunLoopAnonymous
November 17, 2013
Thank you! I know most of that, just File.GetDirectories gave me arrays I thought will be interacted as Array (.SetValue, .GetValue and theese) class, not dimensional variable... which is 100X simplier! Thanks again, iif you want to see result go on www.jkelava6projects.wordpress.com, I'll put new game(Mover 2) up soon(probably), and maku sure you catch comething of it! Greetings, jkelava6Anonymous
November 16, 2014
This is beautiful but doesn't help me dribbleAnonymous
February 13, 2017
Hi, My name is Roy (I'm 66 years old), I have a very difficult problem to program: it amounts to finding all subsets of a set of 50 to 100 integers, taking the reciprocals of the products in each subset and subtracting even subsets from odd subsets. Have not programmed since college other than Excel macros. I tried to learn Java for this problem and I felt restricted and overwhelmed, but with Small Basic I feel I may have a chance to write a program because of the branching operators allowed. Just saying THANKS. Would welcome any suggestions.