RE: Fruit basket program in Ruby.NET

  • From: "Macarty, Jay {PBSG}" <Jay.Macarty@xxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Sat, 5 Jan 2008 12:35:13 -0600

Jamal,
Have not heard of Ruby.net. This is interesting. Where can I get it?
 

-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Jamal Mazrui
Sent: Saturday, January 05, 2008 8:42 AM
To: programmingblind@xxxxxxxxxxxxx
Subject: Re: Fruit basket program in Ruby.NET

Perceptive questions -- I could not do those things initially!  Your
message prompted me to research further, however, and I think I found
solutions that were not well-documented.  The statement
include System::Windows::Forms
imports the namespace as desired.  The
parameter
/t:winexe
compiles a Windows rather than console mode executable.  I have
reposted the archive with these changes at the same URL
http://www.EmpowermentZone.com/rbn_fruit.zip

I am also pasting the revised source code below.

Jamal
# content of rbn_fruit.rb
# Fruit Basket program in Ruby.NET
# Public domain by Jamal Mazrui

# Reference libraries
["mscorlib.dll", "System.dll", "System.Windows.Forms.dll"].each {|dll|
require(dll)}

# Import namespace
include System::Windows::Forms

# Create controls
tlp = TableLayoutPanel.new
tlp.ColumnCount = 3
tlp.RowCount = 2

lblFruit =  Label.new
lblFruit.Text = "&Fruit:"

txtFruit =  TextBox.new

btnAdd =  Button.new
btnAdd.Text = "&Add"

lblBasket =  Label.new
lblBasket.Text = "&Basket:"

lstBasket =  ListBox.new

btnDelete =  Button.new
btnDelete.Text = "&Delete"

[lblFruit, txtFruit, btnAdd, lblBasket, lstBasket, btnDelete].each
{|ctl|
tlp.Controls.Add(ctl)}

# Define Add event handler
btnAdd.add_Click do
sFruit = txtFruit.Text.Trim
if sFruit.Length == 0
 MessageBox.Show("No fruit to add!", "Alert")
else
lstBasket.Items.Add(sFruit)
txtFruit.Clear
iFruit = lstBasket.Items.Count - 1
lstBasket.SelectedIndex = iFruit
end
end

# Define Delete event handler
btnDelete.add_Click do
iFruit = lstBasket.SelectedIndex
if iFruit == -1
 MessageBox.Show("No fruit to delete!", "Alert")
else
lstBasket.Items.RemoveAt(iFruit)
iFruit -= 1 if iFruit = lstBasket.Items.Count
lstBasket.SelectedIndex = iFruit
end
end

# Finalize dialog
dlg =  Form.new
dlg.Text = "Fruit Basket"
dlg.AcceptButton = btnAdd
dlg.StartPosition =  FormStartPosition.CenterScreen
dlg.AutoSize = true
dlg.AutoSizeMode =  AutoSizeMode.GrowAndShrink
dlg.Controls.Add(tlp)
dlg.ShowDialog

# End of rbn_fruit.rb


On Sat, 5 Jan
2008,
Octavian Rasnita wrote:

> Date: Sat, 5 Jan 2008 11:11:19 +0200
> From: Octavian Rasnita <orasnita@xxxxxxxxx>
> Reply-To: programmingblind@xxxxxxxxxxxxx
> To: programmingblind@xxxxxxxxxxxxx
> Subject: Re: Fruit basket program in Ruby.NET
>
> Hi,
>
> Can it be made using...
> #using System.Windows.Forms;
> ...
>
> without needing to specify the fully qualified class name in the
program
> each time?
>
> And... can it be made for not showing the MS DOS command prompt when
it is
> launched?
>
>
> Octavian
>
> ----- Original Message -----
> From: "Jamal Mazrui" <empower@xxxxxxxxx>
> To: <programmingblind@xxxxxxxxxxxxx>
> Sent: Saturday, January 05, 2008 6:59 AM
> Subject: Fruit basket program in Ruby.NET
>
>
> > From the archive
> > http://www.EmpowermentZone.com/rbn_fruit.zip
> >
> > This fruit basket program is written in Ruby.NET:  a version of the
Ruby
> > language hosted at
> > http://rubydotnet.googlegroups.com/web/Home.htm
> >
> > The official home of Ruby is
> > http://ruby-lang.org
> >
> > Ruby.NET was originally developed at a university in Australia,
supported
> > by a grant from Microsoft Future Technologies.  Later, the open
source
> > model was adopted, and development continues as a collaborative
effort of
> > the Ruby community.
> >
> > Note that another Ruby version based on the .NET platform is
IronRuby,
> > being developed in-house at Microsoft, with a web presence at
> > http://ironruby.rubyforge.org/
> >
> > That version is a younger and less complete implementation of Ruby
so far.
> >
> > A batch file in this archive, compile.bat, creates the executable
> > rbn_fruit.exe, which is about 24 KB in size.  Several related DLL
files
> > are also needed -- placed either in the program directory or global
> > assembly cache -- for a combined size of about 1.5 MB.
> >
> > Jamal
> >
> > # content of rbn_fruit.rb
> > # Fruit Basket program in Ruby.NET
> > # Public domain by Jamal Mazrui
> >
> > # Import namespaces
> > require "mscorlib.dll"
> > require "System.dll"
> > require "System.Deployment.dll"
> > require "System.Drawing.dll"
> > require "System.Windows.Forms.dll"
> >
> > # Create controls
> > tlp = System::Windows::Forms::TableLayoutPanel.new
> > tlp.ColumnCount = 3
> > tlp.RowCount = 2
> >
> > lblFruit = System::Windows::Forms::Label.new
> > lblFruit.Text = "&Fruit:"
> >
> > txtFruit = System::Windows::Forms::TextBox.new
> >
> > btnAdd = System::Windows::Forms::Button.new
> > btnAdd.Text = "&Add"
> >
> > lblBasket = System::Windows::Forms::Label.new
> > lblBasket.Text = "&Basket:"
> >
> > lstBasket = System::Windows::Forms::ListBox.new
> >
> > btnDelete = System::Windows::Forms::Button.new
> > btnDelete.Text = "&Delete"
> >
> > [lblFruit, txtFruit, btnAdd, lblBasket, lstBasket, btnDelete].each
{|ctl|
> > tlp.Controls.Add(ctl)}
> >
> > # Define Add event handler
> > btnAdd.add_Click do
> > sFruit = txtFruit.Text.Trim
> > if sFruit.Length == 0
> > System::Windows::Forms::MessageBox.Show("No fruit to add!", "Alert")
> > else
> > lstBasket.Items.Add(sFruit)
> > txtFruit.Clear
> > iFruit = lstBasket.Items.Count - 1
> > lstBasket.SelectedIndex = iFruit
> > end
> > end
> >
> > # Define Delete event handler
> > btnDelete.add_Click do
> > iFruit = lstBasket.SelectedIndex
> > if iFruit == -1
> > System::Windows::Forms::MessageBox.Show("No fruit to delete!",
"Alert")
> > else
> > lstBasket.Items.RemoveAt(iFruit)
> > iFruit -= 1 if iFruit = lstBasket.Items.Count
> > lstBasket.SelectedIndex = iFruit
> > end
> > end
> >
> > # Finalize dialog
> > dlg = System::Windows::Forms::Form.new
> > dlg.Text = "Fruit Basket"
> > dlg.AcceptButton = btnAdd
> > dlg.StartPosition =
System::Windows::Forms::FormStartPosition.CenterScreen
> > dlg.AutoSize = true
> > dlg.AutoSizeMode =
System::Windows::Forms::AutoSizeMode.GrowAndShrink
> > dlg.Controls.Add(tlp)
> > dlg.ShowDialog
> >
> > # End of rbn_fruit.rb
> >
> >
> > __________
> > View the list's information and change your settings at
> > //www.freelists.org/list/programmingblind
> >
>
> __________
> View the list's information and change your settings at
> //www.freelists.org/list/programmingblind
>
__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind
__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

Other related posts: