This article highlights a known issue in Microsoft Small Basic and explains a work around.  This issue may be considered expected behaviour rather than a bug.  If you don't like this behaviour then the "work round" may well be here to stay.


In following sample code, variable c in line 8 sometimes becomes "".  So, output of this program has series of commas.
But in line 15, arry is assigned so c should not be "" (null text).

1.GraphicsWindow.Title = "Array Test"
2.shpTxt = Shapes.AddText("")
3.Shapes.Move(shpTxt, 10, 10)
4.GraphicsWindow.KeyDown = OnKeyDown
5.While "True"
6.  If out < in Then
7.    out = out + 1
8.    c = arry[out]
9.    buf = buf + c + ","
10.    Shapes.SetText(shpTxt, buf)
11.  EndIf
13.Sub OnKeyDown
14.  in = in + 1
15.  arry[in] = GraphicsWindow.LastKey

Possible Cause

Between line 14 and 15 in a mouse handler, lines 6 to 8 in main code interrupt and are executed.  This means that main and event handlers are interrupted by each other.


To avoid this issue, don't assume that event handlers run with higher priority than main.  Following code will be a good solution in this case.

14.  arry[in + 1] = GraphicsWindow.LastKey
15.  in = in + 1

Following program can check this issue with/without solution.

  • Solution for this issue (HHS179-1) - Hit space to toggle solution.  Hit enter for line feed in output.

See Also