Share via


Small Basic: Errors

This article is about errors in the Microsoft Small Basic program language.  If you know other errors, please add them to this article.

Syntax Errors

When you push [Run] button, two processes are started.  The first is compilation.  The Small Basic Environment (SB.exe) calls compiler (SmallBasicCompiler.exe) to compile Small Basic source code to msil for the .NET Framework.  The second process is to run that compiled code.  The Small Basic Environment calls the generated binary.

At compilation time, the compiler checks the syntax of the source code.  If there are any errors in it, the Small Basic Environment shows syntax errors.  Following message is a sample of a syntax error.  "1, 1:" means the number of line (row) and column of the error in the source code.

Sorry, we found some errors…
1,1: Subroutine 'Foo' is not defined.

These kind of syntax errors are listed on bottom in the active editor.  If you click a line of error messages, the cursor will be moved to the line of the source code.

The variable 'xxx' is used, but its value is not assigned.

This error occurs if some variable is not initialized in the code at all.  Following articles describes about one of a case of this errors.
Small Basic Known Issue: 26720 - Event Subroutines Should Be After They Are Registered

Syntax Error Message

The variable 'xxx' is used, but its value is not assigned.  Are you sure you have spelled it correctly?

Syntax Error Message (v1.3~)

I need to use the variable 'xxx' but it has never been given a value. Is this the right name?

Sample Code

Following code occurs this error.

a = b
TextWindow.WriteLine("a=" + a)

But following code doesn't occur this error.

a = b
TextWindow.WriteLine("a=" + a)
b = a
TextWindow.WriteLine("b=" + b)

Access is denied.

This error occurs when one of the programs in Small Basic\Samples folder is attempt to be run.

Syntax Error Message

Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

The file cannot be accessed by the system.

This error occurs when the exe or SmallBasicLibrary.dll in current folder are available only online of your OneDrive. (This error was happened with old OneDrive.)

Syntax Error Message

The file cannot be accessed by the system. (Exception from HRESULT: 0x80070780)

N unexpected at this location.

This error occurs if a number is located the top of a line.

Syntax Error Message

N unexpected at this location.

Syntax Error Message (v1.3~)

I found 'N’ here when I was not expecting it.

Sample Code

3 + y =  x

Operation 'Xxx.Xxx' is supplied N arguments, but takes M arguments.

If a number of arguments (parameters) of an operation is different, following error will occur.

Syntax Error Message

Operation 'Xxx.Xxx' is supplied N arguments, but takes M arguments.

Syntax Error Message (v1.3~)

I was not able to run 'Xxx.Xxx' because it needs N arguments, but here it got M arguments instead.

Sample Code

TextWindow.Write("Number (0-15)? ")
decimal  = TextWindow.ReadNumber()
txt = "0123456789ABCDEF"
subtxt = Text.GetSubText(txt, number +  1)
TextWindow.WriteLine(subtxt)
TextWindow.WriteLine("Hello, " name)

Cannot find operation 'Opxxx' in 'Objxxx'.

This error occurs when the operation Opxxx is not included in an object Objxxx. 

Syntax Error Message

Cannot find operation 'Opxxx' in 'Objxxx'.

Syntax Error Message (v1.3~)

I was unable to find 'Opxxx' in 'Objxxx'.

Sample Code

Text.WriteLine("Hello World!")

Cannot find property 'Prxxx' in 'Objxxx'.

This error occurs when the property Prxxx is not included in an object Objxxx. 

Syntax Error Message

Cannot find property 'Prxxx' in 'Objxxx'.

Syntax Error Message (v1.3~)

I was unable to find a property named 'Prxxx' in 'Objxxx'.

Sample Code

Timer.Tick = Shapes.Move(invador[1], inx[1], iny[1])

Subroutine 'Xxx' is not defined.

If called subroutine is not defined, this error will occur.

Syntax Error Message

Subroutine 'Xxx' is not defined.

Syntax Error Message (v1.3~)

I was unable to find a find a Sub named 'Xxx'.

Sample Code

Foo()
Sub Bar
  TextWindow.WriteLine("Bar")
EndSub

The operation 'Objxxx.Opxxx' is expected a return value.

This error occurs when the operation written in right-hand side of assignment statement doesn't have return value. 

Syntax Error Message

The operation 'Objxxx.Opxxx' is expected a return value, but it doesn't return anything.

Syntax Error Message (v1.3~)

I expected to get a value from 'Objxxx.Opxxx' but it doesn't return anything.

Sample Code

Timer.Tick = Shapes.Move(invador[1], inx[1], iny[1])

Expected EndXxx but could not find one in the right place.

This error occurs if there is a keyword in an illegal place.

Syntax Error Message

Expected EndXxx but could not find one in the right place.

Syntax Error Message (v1.3~)

A Xxx statement must end with EndXxx. I could not find EndXxx in the right place.

Sample Code

If c =  " " Then

Unexpected token Xxx found.

This error occurs if there is a keyword in an illegal place.

Syntax Error Message

Unexpected token Xxx found.

Syntax Error Message (v1.3~)

I found 'Xxx' when I was not expecting it.

Sample Code

While c =  " " Then

Unrecognized statement encountered.

This error occurs if a line has wrong syntax.

Syntax Error Message

Unrecognized statement encountered.

Syntax Error Message (v1.3~)

I was unable to understand this statement.

Sample Code

x + y =  x

Cannot find property 'Prxxx' in 'Objxxx'.

This error occurs when the program runs in browser with Silverlight.

Run Time Errors

At running time, if there happens a trouble in Small Basic library, .NET Framework or Windows system, error popup will be displayed like below.  In the text box, there is a stack trace.  This includes names of subroutines which are called.

After an error popup, you may see following popup which shows the program has stopped working.

If you have installed Visual Studio, you will see "Debug the program" as follows.

You can see the problem details by pushing [v] button beside "View problem details".

Attempted to divide by zero.

Divided by zero causes this error from Small Basic 1.2.

Exception has been thrown by the target of an invocation.

Following actions cause this error.

  • GraphicsWindow.FillRectangle(0, 0, -1, -1)
  • Shapes.AddText() at the program top (Fixed for Small Basic v1.2)
  • GraphicsWindow.GetPixel(x, y) while x < 0 (Fixed for Small Basic v1.2)

Length cannot be less than zero.

If the length in Text.GetSubText(text, start, length) is less than zero, following error will occurs.

Sample Code

txt = "abcdefghijklmnopqrstuvwxyz"
start = 1
length = -1
subtxt = Text.GetSubText(txt, start,  length)
TextWindow.WriteLine(subtxt)

'maxValue' must be greater than zero.

If the maxValue in Math.GetRandomNumber(maxValue) is less than zero, following error will occurs.

Object reference not set to an instance of an object.

Referencing GraphicsWindow.LastText before any text input causes this error.

Specified cast is not valid.

Shapes.GetOpacity() causes following error.  Detail of this error is described in a TechNet article Small Basic Known Issue: 24406 - Shapes.GetOpacity() Causes Cast Error.

The request is not supported.

Following code causes this error in Windows 8.1. (Fixed for Small Basic v1.2)

TextWindow.WriteLine("Here")
TextWindow.Hide()
TextWindow.Show()

Value was either too large or too small for a Decimal.

If a value of a variable is larger than 79228162514264337593543950335 (2^96-1) or smaller than -79228162514264337593543950335 (-2^96+1) then following error occurs.  Also Math.Remainder(x, 0) causes this error.

Sample Code

num = 1
While "True"
  GraphicsWindow.Title = num
  num = num  * 10
EndWhile

Value was either too large or too small for an Int32.

An internal type Int32 allows from -2147483648 (-2^31) to 2147483647 (2^31-1) .  If the parameter of Math.GetRandomNumber() operation is out of the latter range, following error occurs.

File Errors

Most of File operations return "FAILED" if an error occurs.  At that time, File.LastError property contains the error details.  See more details here for file errors.

Access to the path 'X:\Xxx\..\Xxx.Xxx' is denined.

If the output file is read-only, this error is set in File.LastError property.

Other Errors

Microsoft Visual Basic was not found on your machine.

If Visual Basic is not installed this error occurs at graduate.  Visual Basic is included in Visual Studio 2013.  If only Visual Studio 2015 is installed, the same error occurs.  The link in this message is old.  See here for the new URL.

See Also

Other Languages