Asked by:
July Challenge: Code Sample

General discussion
-
Once I read someone asked "Is there sample code for each operation of Small Basic?" (I forgot where and who...)
My suggestion is to write simple sample codes for following categories in Small Basic.
Keywords
- If Then ElseIf Else EndIf
- For To Step EndFor
- While EndWhile
- Sub EndSub
- Goto
Operators
- =
- + - * /
- And Or
Objects (properties / operations / events)
- Array
- Clock
- Controls
- Desktop
- Dictionary
- File
- Flickr
- ...
Nonki Takahashi
- Edited by Ed Price - MSFTMicrosoft employee Thursday, July 21, 2016 7:31 AM Updated title to sticky it
Saturday, June 11, 2016 7:20 AM
All replies
-
-
- Edited by Nonki Takahashi Thursday, June 23, 2016 9:14 PM minor update
Thursday, June 23, 2016 9:10 PM -
This is my version for While EndWhile statement
The turtle start drawing random circles with colors.
The While y <> 6 is the key to stop the drawing where you want, and stop the program to run.
program no: VXQ678
Saturday, July 2, 2016 3:21 PMAnswerer -
This is my version for While EndWhile statement
The turtle start drawing random circles with colors.
The While y <> 6 is the key to stop the drawing where you want, and stop the program to run.
program no: VXQ678
Nonki Takahashi
Monday, July 4, 2016 10:08 AM -
For Keywords, I found examples in help of Small Basic IDE.
' Following code initializes a variable flip for If statement example. [*] coin = "1=Head;2=Tail;" flip = coin[Math.GetRandomNumber(2)] ' If ' The If statement allows you to make decisions to do different things. ' Example ' The following example will print out either "Win" or "Lose" depending on the outcome of ' the flip. If flip = "Tail" Then TextWindow.WriteLine("Win") Else TextWindow.WriteLine("Lose") EndIf ' For ' The For statement allows you to execute a set of statements multiple times. ' Example ' The following example will print out numbers from 1 to 10 For i = 1 To 10 TextWindow.WriteLine(i) EndFor ' While ' The While statement allows you to repeat something until you achieve a desired result. ' Example ' The following code will print a set of random numbers until one that is greater than 100 ' is encountered. While i < 100 i = Math.GetRandomNumber(150) TextWindow.WriteLine(i) EndWhile ' Following line shows how to call a subroutine. [*] Win() ' Sub ' The Sub (Subroutine) statement allows you to do groups of things with a single call. ' Example ' The following example defines a subroutine that rings the bell and prints "Win". Sub Win Sound.PlayBellRing() TextWindow.WriteLine("Win!") EndSub ' This line is to wait before starting example for Goto statement. [*] TextWindow.Pause() ' Goto ' The Goto statement allows branching to a new location in the program. ' Example ' The following program will print consecutive numbers endlessly. start: TextWindow.WriteLine(i) i = i + 1 Goto start
Lines with [*] are added to complete the examples.
Nonki Takahashi
- Edited by Nonki Takahashi Monday, July 4, 2016 10:57 AM wording
Monday, July 4, 2016 10:15 AM -
Here is some samples for the statement: Sound.Playmusic
program no: JPN513
for musical symbols:
https://en.wikipedia.org/wiki/List_of_musical_symbols
- Edited by YLedEditor Wednesday, July 20, 2016 5:12 PM
Wednesday, July 20, 2016 5:06 PMAnswerer -
I wrote a blog about sample codes.
Small Basic - Gather Code SamplesAnd, created a TechNet Wiki article also.
Small Basic: Sample Code
Nonki Takahashi
- Edited by Nonki Takahashi Friday, July 22, 2016 6:50 AM grammar
Friday, July 22, 2016 6:18 AM -
update: VXQ678-0
- nicer colors
- faster draw
- less codelines
Friday, July 22, 2016 1:46 PM -
Monday, August 15, 2016 1:06 PM