It's time for another guest blogger! This one is from Noah Buscher.
Find the latest version of this article on TechNet Wiki: Small Basic: How to Create an Extension Using VB.NET
This article is about how to create a simple extension that you can build on for Small Basic (Microsoft). To get started you will need Small Basic, .NET Framework 3.5, and Visual Basic.NET 10. If you wish to see a tutorial for writing an extension in C#, click here.
STEP 1: Create an Extension
- Open Visual Basic and click on "Create New Project"
- Click on "Class Library" and name it "MyFirstExtension"
- After the project has loaded, delete all the code from Class1, and paste in the following code:
Imports
System
Imports
Microsoft.SmallBasic.Library
Imports
System.Threading
Imports
System.IO
<SmallBasicType()> _
Public
Module
FirstModule
Public
Function
ShowMessage(
ByVal
MsgTxt
As
Primitive)
As
Primitive
MsgBox(MsgTxt.ToString)
End
Function
End
Module
- Open the Solution Explorer and right-click on "MyFirstExtension" and go down to "Add Resource"
- After the dialog opens click on the "Browse" tab and go to your Small Basic folder and click on "SmallBasicLibrary.dll"
- That should take away all the errors
STEP 2: Make it Work
To allow the extension to work in Small Basic, we need to change the Target Framework to .NET 3.5.
- Click on the Save button at the top of the screen
- Go to Projects>MyFirstExtension Properties
- Click on the "Compile" tab
- Click on "Advanced Compile Options" at the bottom
- Click on the drop-down for "Target Framework" and select .NET 3.5
- Click "OK" and when the dialog pops up, click "Yes"
- You can reopen the extension by opening the Solution Explorer and double-clicking on "Class1.VB"
- Now, build the .dll by going to the top of the screen and clicking on Debug>Build MyFirstExtension
- This will build the .dll to the "bin>Release" folder in the project
- Go to the "bin>Release" file in File Explorer and copy all the files, except all the ones named "SmallBasicLibrary.dll" and "SmallBasicLibrary.xml"
- Open Small Basic's folder and create a "lib" folder if there is already not one there
- Open the "lib" folder and paste the programs inside YOU MAY NEED ADMIN PRIVILEGES TO DO THIS
- Close Small Basic if it is open and re-open it
- Now, all you have to do to use the extension is type in FirstModule.ShowMessage("YourMessageBoxTextHere")
STEP 3: Moving On
To create more functions in the FirstModule, all you have to do is add more functions. If you need to get any variables from the user, just separate the ByVal YOURVARIABLE with commas. If you need to return a function, just put return before it like:
Public
Function
NetOpen()
As
Primitive
Return
My.Computer.Network.IsAvailable
End
Function
If you would like a Small Basic Extension with tons of functions, just visit List of SmallBasic Extensions to get it! Remember, the Small Basic community is active, so feel free to ask questions. Good luck!