Microsoft Small Basic

Program Listing:
Embed this in your website
CR = Text.GetCharacter(13)
LF = Text.GetCharacter(10)
GraphicsWindow.BackgroundColor = "LightGray"
GraphicsWindow.BrushColor = "Black"
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
tb = Controls.AddMultiLineTextBox(0, 0)
Controls.SetSize(tb, gw, gh - 30)
Controls.AddButton("Enter", gw - 50, gh - 30)
Controls.ButtonClicked = OnButtonClicked
Sub OnButtonClicked
  buf = Controls.GetTextBoxText(tb)
  ConvertTextToLines()
  ShowLines()
EndSub
Sub ConvertTextToLines
  len = Text.GetLength(buf)
  nLines = 0
  ptr = 1
  While ptr <= len
    eol = Text.GetIndexOf(Text.GetSubTextToEnd(buf, ptr), CR)
    If eol =  0 Then ' eol not found
      nLines = nLines + 1
      lines[nLines] = Text.GetSubTextToEnd(buf, ptr)
      ptr = len + 1
    Else ' eol found
      nLines = nLines + 1
      lines[nLines] = Text.GetSubText(buf, ptr, eol - 1)
      ptr = ptr + eol
      If Text.GetSubText(buf, ptr, 1) = LF Then
        ptr = ptr + 1
      EndIf
    EndIf
  EndWhile
EndSub
Sub ShowLines
  For i =  1 To nLines
    TextWindow.WriteLine("lines[" + i  + "]: " + lines[i])
  EndFor
EndSub
Copyright (c) Microsoft Corporation. All rights reserved.