Small Basic with PowerShell


Do you know that a Small Basic program can be run as a command?

Today I'd like to introduce my CUI (character user interface) program WordList (BKM132-2) and how it will work with PowerShell.

WordList

This program reads a text file and outputs a word list to the text window.  One way to run this program is from the Small Basic Environment (IDE).  The other way is from command prompt.  Save this program as WordList.sb and run once with IDE, then WordList.exe will be created.  WordList can get filename as an argument using Program.GetArgument() like below.

Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.

C:\Users\nonki>cd onedrive\documents\smallbasic\wordlist

C:\Users\nonki\OneDrive\Documents\SmallBasic\WordList>WordList challenge.txt

C:\Users\nonki\OneDrive\Documents\SmallBasic\WordList>

And the result will be like below in the text window.

1 These challenges are intended for people who are learning to program for the
2 first time or for those returning to programming who want to start using
3 SmallBasic.  Some will be easy, some will be hard - but they will all make
4 you think, and more importantly be GREAT FUN!

to ... 1
or ... 2
to ... 2, 2
be ... 3, 3, 4
are ... 1
for ... 1
who ... 1
are ... 1
for ... 1, 2
who ... 2
but ... 3
all ... 3
you ... 4
and ... 4
time ... 2
want ... 2
Some ... 3
will ... 3
easy ... 3
some ... 3
will ... 3
hard ... 3
they ... 3
will ... 3
make ... 3
more ... 4
FUN! ... 4
These ... 1
the ... 1
first ... 2
those ... 2
start ... 2
using ... 2
think ... 4
GREAT ... 4
people ... 1
program ... 1
intended ... 1
learning ... 1
returning ... 2
challenges ... 1
SmallBasic ... 3
programming ... 2
importantly ... 4
Press any key to continue...

PowerShell

And the newest command prompt is PowerShell.  You can use .NET Framework functions in PowerShell.

Windows PowerShell
Copyright (C) 2016 Microsoft Corporation. All rights reserved.

PS C:\Users\nonki> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.14393.953
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.953
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1


PS C:\Users\nonki> cd onedrive\documents\smallbasic\wordlist
PS C:\Users\nonki\onedrive\documents\smallbasic\wordlist> .\wordlist challenge.txt
PS C:\Users\nonki\onedrive\documents\smallbasic\wordlist>

The result will be the same as above in the text window.

Application Mode Changer

One more thing I'd like to introduce today is Application Mode Changer.  I knew this utility program by Pappa Lapub in a forum thread.

Screen shot of a program Application Mode Changer

After changing WordList to a console application, the result of TextWindow.WriteLine() will be output to the console as like below.

FUN! ... 4
These ... 1
the ... 1
first ... 2
those ... 2
start ... 2
using ... 2
think ... 4
GREAT ... 4
people ... 1
program ... 1
intended ... 1
learning ... 1
returning ... 2
challenges ... 1
SmallBasic ... 3
programming ... 2
importantly ... 4
Press any key to continue...
PS C:\Users\nonki\onedrive\documents\smallbasic\wordlist>

This means that we can use output redirect with Small Basic program.  And following list shows using sort command through pipeline from WordList.

PS C:\Users\nonki\onedrive\documents\smallbasic\wordlist> .\wordlist challenge.txt | sort

1 These challenges are intended for people who are learning to program for the
2 first time or for those returning to programming who want to start using
3 SmallBasic.  Some will be easy, some will be hard - but they will all make
4 you think, and more importantly be GREAT FUN!
all ... 3
and ... 4
are ... 1
are ... 1
be ... 3, 3, 4
but ... 3
challenges ... 1
easy ... 3
first ... 2
for ... 1
for ... 1, 2
FUN! ... 4
GREAT ... 4
hard ... 3
importantly ... 4
intended ... 1
learning ... 1
make ... 3
more ... 4
or ... 2
people ... 1
Press any key to continue...
program ... 1

Input redirect for Small Basic program didn't work well because the end of file will be passed as null but Small Basic can't treat the null and causes error.

Anyway, with PowerShell, we can explore the possibility of Small Basic programs.

See Also

Comments (2)

  1. runwayug says:

    that URL of WordList (BKM132-2) is wrong.

    http://smallbsic.com/program/?BKM132-2 <- wrong

    http://smallbasic.com/program/?BKM132-2 <- correct

    1. Hello, runwayug. Thank you for your information. I just corrected.

Skip to main content