Small Basic: How to Create an Extension Using VB.NET

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


  1. Open Visual Basic and click on "Create New Project"
  2. Click on "Class Library" and name it "MyFirstExtension"
  3. After the project has loaded, delete all the code from Class1, and paste in the following code:
  4. 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

  5. Open the Solution Explorer and right-click on "MyFirstExtension" and go down to "Add Resource"
  6. After the dialog opens click on the "Browse" tab and go to your Small Basic folder and click on "SmallBasicLibrary.dll"
  7. 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.
  1. Click on the Save button at the top of the screen
  2. Go to Projects>MyFirstExtension Properties
  3. Click on the "Compile" tab
  4. Click on "Advanced Compile Options" at the bottom
  5. Click on the drop-down for "Target Framework" and select .NET 3.5
  6. Click "OK" and when the dialog pops up, click "Yes"
  7. You can reopen the extension by opening the Solution Explorer and double-clicking on "Class1.VB"
  8. Now, build the .dll by going to the top of the screen and clicking on Debug>Build MyFirstExtension
  9. This will build the .dll to the "bin>Release" folder in the project
  10. Go to the "bin>Release" file in File Explorer and copy all the files, except all the ones named "SmallBasicLibrary.dll" and "SmallBasicLibrary.xml"
  11. Open Small Basic's folder and create a "lib" folder if there is already not one there
  12. Open the "lib" folder and paste the programs inside YOU MAY NEED ADMIN PRIVILEGES TO DO THIS
  13. Close Small Basic if it is open and re-open it
  14. 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!


Other Languages

Leave a Comment
  • Please add 5 and 7 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
Comments
  • Richard Mueller edited Revision 24. Comment: Removed tags "small", "visual", "basic", and "Has Comments". Changed tags "how" and "to" to "How To".

  • Nonki Takahashi edited Revision 22. Comment: link

  • Ed Price - MSFT edited Revision 21. Comment: Removed the rest of the bold from Step 2

  • Ed Price - MSFT edited Revision 20. Comment: Removing the bold from the "Step 2" section

  • Ed Price - MSFT edited Revision 15. Comment: Retitling for consistency

  • Ed Price - MSFT edited Revision 9. Comment: White space tweaks

  • Ed Price - MSFT edited Revision 8. Comment: Adding TOC and tags

  • Patris_70 edited Revision 2. Comment: added en-US title

Page 1 of 1 (8 items)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Comments
  • Patris_70 edited Revision 2. Comment: added en-US title

  • Step 2: (10) - I think only MyFirstExtension.dll and MyFirstExtension.xml are needed.  But My MyFirstExtension.pdb is not needed.

  • There is a good article "Extending Small Basic" in Small Basic Blog.  blogs.msdn.com/.../extending-small-basic.aspx

  • Ed Price - MSFT edited Revision 8. Comment: Adding TOC and tags

  • Ed Price - MSFT edited Revision 9. Comment: White space tweaks

  • Hey, nice tutorial. But I stuck at Step 2, Part 5.

    I ever get this ERROR if I try to change the Framework...

    [IMG]i50.tinypic.com/10n7plf.jpg[/IMG]

    But I saved the projekt!

  • Hey, nice tutorial. But I stuck at Step 2, Part 5.

    I ever get this ERROR if I try to change the Framework...

    [IMG]i50.tinypic.com/10n7plf.jpg[/IMG]

    But I saved the projekt!

  • Ed Price - MSFT edited Revision 15. Comment: Retitling for consistency

  • Ed Price - MSFT edited Revision 20. Comment: Removing the bold from the "Step 2" section

  • Ed Price - MSFT edited Revision 21. Comment: Removed the rest of the bold from Step 2

  • @Timo So: Can you please translate that to English?

  • Here is the translation: The current project must be saved before you change the target framework.

    The problem is that I saved the program around 50 times before I tried to do this. I did not change anything after the last save.

  • Nonki Takahashi edited Revision 22. Comment: link

  • I have added SmallBasicLibrary.dll as a resource, but it still doesn't recognise "Imports Microsoft.SmallBasic.Library" and "<SmallBasicType()> _"

  • Richard Mueller edited Revision 24. Comment: Removed tags "small", "visual", "basic", and "Has Comments". Changed tags "how" and "to" to "How To".

Page 1 of 1 (15 items)