Re: Fruit basket program in Visual Basic 10 with Layout by Code

  • From: Jamal Mazrui <empower@xxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Fri, 25 Jun 2010 04:24:53 -0400

If you would rather distribute an executable as a single file, without seperate .dll assemblies, you can use the ILMerge utility, available at


http://www.microsoft.com/downloads/details.aspx?familyid=22914587-b4ad-4eae-87cf-b14ae6a939b0&displaylang=en

I have now updated the vblbc_fruit.zip archive so that you can merge the Homer.NET assemblies with the fruit basket executable by running the batch file merge.bat after installing IlMerge. vblbc_fruit.exe increases in size from about 8K to 225K. It is then the only file needed to run the program -- as long as .NET 4 is installed.

Jamal

On 6/24/2010 9:14 PM, Jamal Mazrui wrote:
I forgot to mention that, when using EdSharp, first choose the Visual
Basic .NET compiler with Control+Shift+F5. The current CompileCommand
setting for that compiler is not configured for use of Homer.NET. Thus,
you then need to use the Configuration Options dialog, Alt+Shift+C, to
set that option to the string mentioned below.

You would then compile source code with Control+F5. The cursor should
automatically be positioned on the line containing the first compilation
error, if any. You can press Alt+Shift+F5 to review all compiler output.
This assumes you have installed the .NET Framework 4. If not, you can do
so with the GotNET installer, available at

http://EmpowermentZone.com/netsetup.exe

Jamal


On 6/24/2010 3:44 PM, Jamal Mazrui wrote:
From the archive
http://EmpowermentZone.com/vblbc_fruit.zip

This fruit basket is written in Visual Basic 10 (which was released in
April, 2010). It uses the Homer.NET library, distributed with the Homer
application framework, HomerApp, available at
http://EmpowermentZone.com/appsetup.exe

or .zip for a manual install.

Five Homer.NET assemblies, matching Homer*.dll, need to be included in
the same directory as the executable, vblbc_fruit.exe. The batch file,
compile.bat, builds the executable using the Visual Basic command-line
compiler, vbc.exe, based on the source code, vblbc_fruit.vb.

A compiler response file, Homer.rsp, sets most compiler parameters. This
response file can also be used to compile VB programs within the EdSharp
editor, available at
http://EmpowermentZone.com/edsetup.exe

To do this, set the CompileCommand setting in the EdSharp Configuration
Options dialog to the following string:

vbc.exe @Homer.rsp "%Source%" 2>&1

The commented source code is also pasted below.

Jamal

' Fruit basket in Visual Basic 10 with Layout by Code
' Public domain by Jamal Mazrui
' June 24, 2010

' Require variables to be explicitly declared
Option Explicit On
' Require type casts to be explicitly done
Option Strict On

' Import namespaces
imports Homer
imports System
imports System.ComponentModel
imports System.Windows.Forms

' Declare a class named 'Dialog' that inherits from the class named
'LbcForm'
Class Dialog
Inherits LbcForm

' Define the main event handler for this form
public Sub OnEvent(sEvent As String, oSender As Object, oArgs As
EventArgs)
' Get references to the TextBox and ListBox widgets of this form
Dim txt As TextBox = me.GetTextBox("Fruit")
Dim lst As ListBox = me.GetListBox("Basket")

' Declare other local variables used in this event handler routine
Dim iCount, iIndex As Integer
Dim sFruit, sWidgetName As String

' Test for an event by name
Select Case sEvent
Case "Closing"
If Lbc.DialogConfirm("Confirm", "Exit program?", "Y") <> "Y" Then
CType(oArgs, CancelEventArgs).Cancel = True
Case "Click"
' Test for a widget by name
sWidgetName = Lbc.GetName(oSender)
Select Case sWidgetName
Case "Button_Add"
sFruit = txt.Text
If sFruit.Length = 0 Then
Lbc.DialogShow("Alert", "No fruit to add!")
Else
lst.Items.Add(sFruit)
iIndex = lst.Items.Count - 1
lst.SelectedIndex = iIndex
txt.Clear()
End If
Case "Button_Delete"
iIndex = lst.SelectedIndex
If iIndex = -1 Then
Lbc.DialogShow("Alert", "No fruit to delete!")
Else
lst.Items.RemoveAt(iIndex)
iCount = lst.Items.Count
If iCount = 0 Then Return
If iIndex = iCount Then iIndex -= 1
lst.SelectedIndex = iIndex
End If
End Select
End Select
End Sub ' OnEvent method

' Define entry point of the program
Shared Sub Main()

' Instantiate an object of the Dialog class
Dim dlg As Dialog = New Dialog()
End Sub ' Main method

' Define the constructor of the Dialog class
Sub New()
' Set the dialog title
me.Init("Fruit Basket")

' Add a 'Fruit' label and a TextBox
me.AddInputBox("Fruit")

' Add a default button named 'Add'
me.AcceptButton = me.AddButton("Add")

' Start a new band of widgets
me.AddBand()

' Add a 'Basket' label and a ListBox
me.AddPickBox("Basket")

' Add a button named 'Delete'
me.AddButton("Delete")

' Complete setup of the dialog and activate it
me.CompleteDialog()
End Sub ' New method
End Class ' Dialog class

__________
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: