Optimized fruit basket program in Boo

  • From: Jamal Mazrui <empower@xxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Sat, 10 Nov 2007 08:31:59 -0500 (EST)

I have revised the archive at
http://www.EmpowermentZone.com/boo_fruit.zip
so that it now contains a version that takes advantage of the intelligence
of the Boo compiler, permitting a more concise and friendly coding style
with types inferred from context.  The resulting executable is the same
12K as before.  I am pasting the source code below.

Jamal


/*
content of optimal.boo
Fruit Basket program in Boo
Public domain by Jamal Mazrui
*/

// Import namespaces
import System
import System.Windows.Forms

// Create dialog and controls
dlg = Form(Text : "Fruit Basket", StartPosition :
FormStartPosition.CenterScreen, Width : 400, Height : 285)
lblFruit = Label(Text : "&Fruit:", Left : 14, Top : 14, Width : 44, Height
: 16)
txtFruit = TextBox( Left : 64, Top : 14, Width : 200, Height : 16)
btnAdd = Button(Text : "&Add", Left : 272, Top : 14, Width : 100, Height :
20)
lblBasket = Label(Text : "&Basket:", Left : 14, Top : 38, Width : 44,
Height : 16)
lstBasket = ListBox(Left : 64, Top : 38, Width : 200, Height : 200)
btnDelete = Button(Text : "&Delete", Left : 272, Top : 38, Width : 100,
Height : 20)
dlg.Controls.AddRange((lblFruit, txtFruit, btnAdd, lblBasket, lstBasket,
btnDelete))

// Define Add event handler
btnAdd.Click += def (o, e):
  sFruit = txtFruit.Text
  if sFruit == "":
    MessageBox.Show("No fruit to add!", "Alert")
    return

  lstBasket.Items.Add(sFruit)
  txtFruit.Text = ""
  lstBasket.SelectedIndex = (lstBasket.Items.Count - 1)

// Define Delete event handler
btnDelete.Click += def (o, e):
  iFruit = lstBasket.SelectedIndex
  if iFruit == (-1):
    MessageBox.Show("No fruit to delete.", "Alert")
    return

  lstBasket.Items.RemoveAt(iFruit)
  if iFruit > (lstBasket.Items.Count - 1): iFruit = (lstBasket.Items.Count
- 1)
  lstBasket.SelectedIndex = iFruit

// Finalize and show dialog
dlg.AcceptButton = btnAdd
dlg.ShowDialog()

__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: