Microsoft Small Basic

Program Listing:
Embed this in your website
' PIN Generator 0.1b
' Copyright (c) 2013 Nonki Takahashi. All right reserved.
'
' History:
' 0.1b 2013-10-16 Created.
'
GraphicsWindow.Title = "PIN Generator 0.1b"
nDigits = 8
Init()
GraphicsWindow.PenWidth = 2
GraphicsWindow.PenColor = "DimGray"
param = "dx=34;dy=34;"
'DrawGrid()
Form()
Controls.ButtonClicked = OnButtonClicked
Controls.TextTyped = OnTextTyped
GraphicsWindow.MouseDown = OnMouseDown
Sub OnTextTyped
  n = Controls.GetTextBoxText(dbox)
  If n + 0 = n Then
    nDigits = n
  Else
    Controls.SetTextBoxText(dbox, nDigits)
  EndIf
EndSub
Sub OnMouseDown
  mx = GraphicsWindow.MouseX
  my = GraphicsWindow.MouseY
  For iCheckBox = 1 To cboxNum
    x0 = cboxObj[iCheckBox]["x0"]
    x1 = cboxObj[iCheckBox]["x1"]
    y0 = cboxObj[iCheckBox]["y0"]
    y1 = cboxObj[iCheckBox]["y1"]
    If x0 <= mx And mx <= x1 And y0 <= my And my <= y1 Then
      If cboxObj[iCheckBox]["checked"] Then
        Shapes.HideShape(cboxObj[iCheckBox]["checkmark"])
        cboxObj[iCheckBox]["checked"] = "false"
      Else
        Shapes.ShowShape(cboxObj[iCheckBox]["checkmark"])
        cboxObj[iCheckBox]["checked"] = "true"
      EndIf
    EndIf
  EndFor
EndSub
Sub OnButtonClicked
  pin = ""
  param["checkBoxName"] = cbox
  IsChecked()
  If return Then
    max = Text.GetLength(na)
  Else
    max = 10
  EndIf
  For iDigits = 1 To nDigits
    pin = Text.Append(pin, Text.GetSubText(na, Math.GetRandomNumber(max), 1))
  EndFor
  Controls.SetTextBoxText(pbox, pin)
EndSub
Sub IsChecked
  iCheckBox = Text.GetSubTextToEnd(param["checkBoxName"], 9)
  return = cboxObj[iCheckBox]["checked"]
EndSub
Sub Init
  gw = 640
  gh = 480
  GraphicsWindow.Width = gw
  GraphicsWindow.Height = gh
  na = "0123456789ACEFGHJKLMNPQRTUVWXY"
  fs = GraphicsWindow.FontSize
  GraphicsWindow.BackgroundColor = "LightGray"
EndSub
Sub Form
  GraphicsWindow.BrushColor = "Black"
  GraphicsWindow.DrawText(34, 34 + fs * 0.3, "Digits")
  dbox = Controls.AddTextBox(34 + fs * 3.5, 34)
  Controls.SetTextBoxText(dbox, nDigits)
  param = "caption=Alphabet;left=34;top=68;"
  AddCheckBox()
  cbox = return
  button = Controls.AddButton("Create", 34, 102)
  pbox = Controls.AddTextBox(34, 136)
EndSub
Sub DrawGrid
  For x = param["dx"] To gw Step param["dx"]
    GraphicsWindow.DrawLine(x, 0, x, gh)
  EndFor
  For y = param["dy"] To gh Step param["dy"]
    GraphicsWindow.DrawLine(0, y, gw, y)
  EndFor
EndSub
Sub AddCheckBox
  ' param["left"] - the x co-ordinate of the check box
  ' param["top"] - the y co-ordinate of the check box
  ' returns return - the check box that was just added to the Graphics Window.
  cboxColor = GraphicsWindow.BrushColor
  cboxSize = GraphicsWindow.FontSize
  cboxFont = GraphicsWindow.FontName
  cboxNum = cboxNum + 1
  cboxX0 = param["left"]
  cboxX1 = cboxX0 + cboxSize + 1
  cboxY0 = param["top"] + 1
  cboxY1 = cboxY0 + cboxSize + 1
  GraphicsWindow.BrushColor = "Gray"
  GraphicsWindow.FillRectangle(cboxX0, cboxY0, cboxSize + 2, cboxSize + 2)
  GraphicsWindow.BrushColor = "White"
  GraphicsWindow.FillRectangle(cboxX0 + 1, cboxY0 + 1, cboxSize, cboxSize)
  cboxObj[cboxNum]["x0"] = cboxX0
  cboxObj[cboxNum]["x1"] = cboxX1
  cboxObj[cboxNum]["y0"] = cboxY0
  cboxObj[cboxNum]["y1"] = cboxY1
  GraphicsWindow.BrushColor = cboxColor
  GraphicsWindow.FontName = "Wingdings 2"
  cboxMark = Shapes.AddText("P")
  Shapes.Move(cboxMark, param["left"] + 1, param["top"] + 3)
  Shapes.HideShape(cboxMark)
  cboxObj[cboxNum]["checkmark"] = cboxMark
  cboxObj[cboxNum]["checked"] = "False"
  GraphicsWindow.FontName = cboxFont
  cboxMark = Shapes.AddText(param["caption"])
  Shapes.Move(cboxMark, param["left"] + cboxSize * 1.5 , param["top"])
  return = "CheckBox" + cboxNum
EndSub

Copyright (c) Microsoft Corporation. All rights reserved.