Google Answers Logo
View Question
 
Q: I need Code for 3 more vb programs ( Answered,   2 Comments )
Question  
Subject: I need Code for 3 more vb programs
Category: Computers
Asked by: googooly-ga
List Price: $25.00
Posted: 11 Feb 2003 21:43 PST
Expires: 13 Mar 2003 21:43 PST
Question ID: 160319
Hi,
I need the code for following 3 more VB programs.
I have limited experience in VB so Code has to be written very simply
so I can understand and modify it
I f you do it quickly and explain what you do in each step then I give
you more project and rate it 5 star

Have fun
googooly


Project 3-1: Display font properties
Operation
·        The user enters text in the text box and then clicks on a
check box or option button.

·        Each time the user clicks, the text in the text box is
modified to show the font change.

Specifications
·        Use the FontBold, FontItalic, and FontUnderline properties to
apply the effects.

·        Use the FontSize property to change the font size.

·        Use the ForeColor property to change the font color.

·        The most efficient way to code this project is to use a
control array for each set of check boxes and option buttons. Then,
you can use the Case structure to apply the appropriate font
properties.





Project 3-2: Manage list box entries
Operation
·        When the user enters text in the text box and clicks on the
Add to list button, the text is added to the bottom of the list in the
list box.

·        When the user highlights a line in the list box and clicks on
the Remove from list button, the line is removed from the list box.

Specifications
·        Use the ListIndex property to determine which item is
selected in the list box. A value of –1 means nothing is selected.

Enhancements
·         Add a Clear button that clears all the entries from the list
box.




Project 3-3: Process lunch orders
Operation
·        For each order, the user selects one main course item and
zero or more of the associated add-ons.

·        When the user clicks on the Place Order button, the
application displays the sub total, tax, and total due for the order.
It also enables the Print Receipt button.

·        To print a copy of the lunch order form, the user can click
on the Print Receipt button. This also clears the add-on check boxes
and resets the Main course option button to Hamburger.

Add-ons
·         The three add-ons and prices change based on the main course
item that’s selected.

·         For a hamburger, the three items are: (1) Lettuce, tomato,
and onions; (2) Mayonnaise and mustard; and (3) French fries. The
price of each is 75 cents.

·         For a pizza, the three items are: (1) Pepperoni, (2)
Sausage, and (3) Olives. The price of each is 50 cents.

·         For a salad, the three items are the ones shown above and
the price of each is 25 cents.

Specifications
·        The sub total is equal to the cost of the main course item,
plus the cost of the add-ons. The tax is the sub total * .0785. And
the total due is the sub total + tax.

·         To print a copy of the lunch order form when the user clicks
on the Print Receipt button, you can use the PrintForm method of the
form object.

·         While you’re testing you may want to comment out the line
that prints the form to save paper and printing time.

Request for Question Clarification by j_philipp-ga on 12 Feb 2003 01:27 PST
Hello Googooly,

Maybe if you break up the three questions, it would be easier to answer.
For which version of Visual Basic do you need the code?
Thanks.

Clarification of Question by googooly-ga on 18 Feb 2003 20:52 PST
j_philipp-ga


yes VB6 and what do you breaking up the three questions.

I need a code that I can just dump it in to vb6 and compile it and I
really need it soon.

igykalen-ga

thank you for the info : )

Request for Question Clarification by j_philipp-ga on 18 Feb 2003 21:34 PST
Googooly,

What I meant is you might have a better chance of having the questions
answered if you post them as three separate questions here on Google
Answers, instead of a bundled version. If then you still don't get an
answer, you might want to think about increasing the question price.
Good luck!
Answer  
Subject: Re: I need Code for 3 more vb programs
Answered By: hammer-ga on 25 Feb 2003 15:40 PST
 
Googooly,

I have written a VB6 project which includes 3 forms. Each form
implements the code for one of your questions. You can download the
project and its files at:
http://www.hammerdata.com/Google/projects3.zip

Unzip the file and everything you need should be there. For each
project, there is a form. The code behind each form is heavily
commented.

Please let me know if you need clarification.

- Hammer

Clarification of Answer by hammer-ga on 25 Feb 2003 15:47 PST
Googooly,

After posting, I noticed that a commenter has also posted some code
while I was working. His code is not as commented as mine, and does
not follow some of the requirements of your project (for example, he
uses combo boxes instead of option buttons in the Font Properties
projects). Becasue of this, I will let my answer stand. Please let me
know if this is a problem.

- Hammer

Clarification of Answer by hammer-ga on 07 Mar 2003 06:00 PST
Googooly,

I notice you have not yet closed/rated this question. Could you please
let me know if you have downloaded your project yet, so I can remove
your file from my download area? Thank you.

- Hammer
Comments  
Subject: Re: I need Code for 3 more vb programs
From: igykalen-ga on 15 Feb 2003 21:47 PST
 
I still program in VB3 :(, but I suspect basic vb code hasn't changed much.
Using the help file might work for you if the code doesn't work exactly right.


Since this is the easiest for me (for free anyway)
Project 3-2: Manage list box entries 
1)
Sub Command1_Click ()
Static num
num = num + 1
list1.AddItem "hi" + num 'additem will simply add to end of list
End Sub

2)
Sub Command2_Click ()
'remove from list highlighted item
On Error Resume Next 'quick fix to prevent error when
                     'trying to remove items not selected
list1.RemoveItem list1.ListIndex
End Sub

3)
>Specifications 
>Use the ListIndex property to determine which item is
>selected in the list box. A value of –1 means nothing is selected.
Not sure what you want. Sounds like you know what your doing here.

Sub Command4_Click ()
label1 = list1.ListIndex 'will display the number value selected
End Sub

Sub Command4_Click ()
label1 = list1.List(list1.ListIndex) 'will display the data entered
End Sub


4)
list1.Clear to clear the listbox and other controls. See methods in help.
Subject: Re: I need Code for 3 more vb programs
From: brentrockwood-ga on 25 Feb 2003 14:45 PST
 
Here's your answer.  Please not that you forgot to list pricing for the
main courses in project 3-3.  I've selected some random prices.  You can change
them in the constants at the top of the form code.

If you would like to download the working project I used, it is at 
http://brentrockwood.com/ga160319.zip.

Please note, if you were paying for this, it would cost you a heck of a lot more
than 25.00. :)

Cheers, Brent

======================== SNIP HERE (frmProj31.frm) ========================
VERSION 5.00
Begin VB.Form frmProj31 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "Project 3-1"
   ClientHeight    =   4710
   ClientLeft      =   45
   ClientTop       =   360
   ClientWidth     =   6705
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   4710
   ScaleWidth      =   6705
   ShowInTaskbar   =   0   'False
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton cmdExit 
      Caption         =   "Exit"
      Height          =   375
      Left            =   5280
      TabIndex        =   3
      Top             =   4200
      Width           =   1335
   End
   Begin VB.Frame fraFont 
      Caption         =   "Font"
      Height          =   1815
      Left            =   2400
      TabIndex        =   2
      Top             =   2160
      Width           =   4215
      Begin VB.ComboBox cboFontColor 
         Height          =   315
         Left            =   720
         Style           =   2  'Dropdown List
         TabIndex        =   9
         Top             =   1320
         Width           =   3255
      End
      Begin VB.ComboBox cboFontSize 
         Height          =   315
         ItemData        =   "frmProj31.frx":0000
         Left            =   720
         List            =   "frmProj31.frx":002B
         Style           =   2  'Dropdown List
         TabIndex        =   6
         Top             =   840
         Width           =   1095
      End
      Begin VB.ComboBox cboFontName 
         Height          =   315
         ItemData        =   "frmProj31.frx":0062
         Left            =   720
         List            =   "frmProj31.frx":0064
         Style           =   2  'Dropdown List
         TabIndex        =   5
         Top             =   360
         Width           =   3255
      End
      Begin VB.Label lblFontColor 
         Caption         =   "Color:"
         Height          =   255
         Left            =   120
         TabIndex        =   10
         Top             =   1380
         Width           =   735
      End
      Begin VB.Label lblFontSize 
         Caption         =   "Size:"
         Height          =   255
         Left            =   120
         TabIndex        =   8
         Top             =   900
         Width           =   855
      End
      Begin VB.Label lblFontName 
         Caption         =   "Name:"
         Height          =   255
         Left            =   120
         TabIndex        =   7
         Top             =   420
         Width           =   975
      End
   End
   Begin VB.Frame fraAttributes 
      Caption         =   "Text Attributes"
      Height          =   1815
      Left            =   120
      TabIndex        =   1
      Top             =   2160
      Width           =   2175
      Begin VB.CheckBox chkAttributes 
         Caption         =   "Underline"
         Height          =   255
         Index           =   2
         Left            =   480
         TabIndex        =   12
         Top             =   1320
         Width           =   975
      End
      Begin VB.CheckBox chkAttributes 
         Caption         =   "Italic"
         Height          =   255
         Index           =   1
         Left            =   480
         TabIndex        =   11
         Top             =   840
         Width           =   1215
      End
      Begin VB.CheckBox chkAttributes 
         Caption         =   "Bold"
         Height          =   255
         Index           =   0
         Left            =   480
         TabIndex        =   4
         Top             =   360
         Width           =   1095
      End
   End
   Begin VB.TextBox txtInput 
      Height          =   1815
      Left            =   120
      MultiLine       =   -1  'True
      OLEDragMode     =   1  'Automatic
      OLEDropMode     =   2  'Automatic
      TabIndex        =   0
      Top             =   120
      Width           =   6495
   End
End
Attribute VB_Name = "frmProj31"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

' The positions of the checkboxes in the chkAttribute array.
Private Enum TextAttributeEnum
    AttrBold = 0
    AttrItalic = 1
    AttrUnderline = 2
End Enum

Private Sub Form_Load()

    ' Initialize the combo boxes.
    
    InitCboFontName
    InitCboFontSize
    InitCboFontColor
End Sub

' Initialize the font name combo.
Private Sub InitCboFontName()
    Dim i As Integer
    Dim strFont As String
    
    cboFontName.Clear
    
    For i = 0 To Screen.FontCount - 1
        cboFontName.AddItem (Screen.Fonts(i))
    Next
    
    cboFontName.Text = txtInput.FontName
End Sub

' Initialize the font size combo.
Private Sub InitCboFontSize()
    cboFontSize.ListIndex = 0
End Sub

' Initialize the font color combo.
Private Sub InitCboFontColor()
    cboFontColor.AddItem ("Black")
    cboFontColor.ItemData(0) = vbBlack
    
    cboFontColor.AddItem ("Red")
    cboFontColor.ItemData(1) = vbRed
    
    cboFontColor.AddItem "Green"
    cboFontColor.ItemData(2) = vbGreen
    
    cboFontColor.AddItem "Yellow"
    cboFontColor.ItemData(3) = vbYellow
    
    cboFontColor.AddItem "Blue"
    cboFontColor.ItemData(4) = vbBlue
    
    cboFontColor.AddItem "Magenta"
    cboFontColor.ItemData(5) = vbMagenta
    
    cboFontColor.AddItem "Cyan"
    cboFontColor.ItemData(6) = vbCyan
    
    cboFontColor.AddItem "White"
    cboFontColor.ItemData(7) = vbWhite
    
    cboFontColor.ListIndex = 0
End Sub

' Applies text attributes to the input textbox when an attribute
' checkbox is clicked.
Private Sub chkAttributes_Click(Index As Integer)
    
    ' As requested, the Attributes use a control array,
    ' and a case statement is used to determine which
    ' checkbox that was clicked.
    
    Select Case Index
        Case TextAttributeEnum.AttrBold
            txtInput.FontBold = CBool(chkAttributes(Index).Value = vbChecked)
        Case TextAttributeEnum.AttrItalic
            txtInput.FontItalic = CBool(chkAttributes(Index).Value = vbChecked)
        Case TextAttributeEnum.AttrUnderline
            txtInput.FontUnderline = CBool(chkAttributes(Index).Value = vbChecked)
    End Select
End Sub

' Applies font change when font name combo is clicked.
Private Sub cboFontName_Click()
    txtInput.FontName = cboFontName.Text
End Sub

' Applies size change when font size combo is clicked.
Private Sub cboFontSize_Click()
    txtInput.FontSize = CSng(cboFontSize.Text)
End Sub

' Applied color change when font color combo is clicked.
Private Sub cboFontColor_Click()
    txtInput.ForeColor = cboFontColor.ItemData(cboFontColor.ListIndex)
End Sub

' Exit and unload the form.
Private Sub cmdExit_Click()
    Unload Me
End Sub
======================== SNIP HERE (frmProj31.frm) ========================

======================== SNIP HERE (frmProj32.frm) ========================
VERSION 5.00
Begin VB.Form frmProj32 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "Project 3-2"
   ClientHeight    =   4260
   ClientLeft      =   45
   ClientTop       =   360
   ClientWidth     =   7080
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   4260
   ScaleWidth      =   7080
   ShowInTaskbar   =   0   'False
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton cmdClear 
      Caption         =   "Clear"
      Height          =   375
      Left            =   5640
      TabIndex        =   5
      Top             =   1200
      Width           =   1335
   End
   Begin VB.CommandButton cmdDelete 
      Caption         =   "Delete"
      Height          =   375
      Left            =   5640
      TabIndex        =   4
      Top             =   720
      Width           =   1335
   End
   Begin VB.ListBox lstMain 
      Height          =   3375
      Left            =   120
      TabIndex        =   3
      Top             =   720
      Width           =   5415
   End
   Begin VB.CommandButton cmdAdd 
      Caption         =   "Add"
      Height          =   375
      Left            =   5640
      TabIndex        =   2
      Top             =   120
      Width           =   1335
   End
   Begin VB.TextBox txtInput 
      Height          =   375
      Left            =   120
      TabIndex        =   1
      Top             =   120
      Width           =   5415
   End
   Begin VB.CommandButton cmdExit 
      Caption         =   "Exit"
      Height          =   375
      Left            =   5640
      TabIndex        =   0
      Top             =   3720
      Width           =   1335
   End
   Begin VB.Line Line2 
      BorderColor     =   &H80000010&
      X1              =   120
      X2              =   6960
      Y1              =   590
      Y2              =   590
   End
   Begin VB.Line Line1 
      BorderColor     =   &H80000014&
      X1              =   120
      X2              =   6960
      Y1              =   605
      Y2              =   605
   End
End
Attribute VB_Name = "frmProj32"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub cmdAdd_Click()
    If Len(txtInput.Text) > 0 Then
        lstMain.AddItem txtInput.Text
    End If
    
    txtInput.Text = ""
End Sub

Private Sub cmdDelete_Click()
    If lstMain.ListIndex >= 0 Then
        lstMain.RemoveItem lstMain.ListIndex
    End If
End Sub

Private Sub cmdClear_Click()
    lstMain.Clear
End Sub

Private Sub cmdExit_Click()
    Unload Me
End Sub

======================== SNIP HERE (frmProj32.frm) ========================

======================== SNIP HERE (frmProj33.frm) ========================
VERSION 5.00
Begin VB.Form frmProj33 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "Project 3-3"
   ClientHeight    =   4935
   ClientLeft      =   45
   ClientTop       =   360
   ClientWidth     =   5535
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   4935
   ScaleWidth      =   5535
   ShowInTaskbar   =   0   'False
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton cmdPrintReceipt 
      Caption         =   "Print Receipt"
      Enabled         =   0   'False
      Height          =   375
      Left            =   4080
      TabIndex        =   15
      Top             =   600
      Width           =   1335
   End
   Begin VB.CommandButton cmdPlaceOrder 
      Caption         =   "Place Order"
      Height          =   375
      Left            =   4080
      TabIndex        =   14
      Top             =   120
      Width           =   1335
   End
   Begin VB.CommandButton cmdExit 
      Caption         =   "Exit"
      Height          =   375
      Left            =   4080
      TabIndex        =   13
      Top             =   4440
      Width           =   1335
   End
   Begin VB.Frame fraReceipt 
      Caption         =   "Receipt"
      Height          =   1935
      Left            =   120
      TabIndex        =   6
      Top             =   2880
      Width           =   3855
      Begin VB.Label lblTotal 
         Alignment       =   1  'Right Justify
         Caption         =   "$0.00"
         Height          =   255
         Left            =   1320
         TabIndex        =   12
         Top             =   1440
         Width           =   975
      End
      Begin VB.Label lblTax 
         Alignment       =   1  'Right Justify
         Caption         =   "0.00"
         Height          =   255
         Left            =   1560
         TabIndex        =   11
         Top             =   960
         Width           =   735
      End
      Begin VB.Label lblSubtotal 
         Alignment       =   1  'Right Justify
         Caption         =   "0.00"
         Height          =   255
         Left            =   1440
         TabIndex        =   10
         Top             =   480
         Width           =   855
      End
      Begin VB.Label lblTotalLegend 
         Caption         =   "Total:"
         Height          =   375
         Left            =   600
         TabIndex        =   9
         Top             =   1440
         Width           =   855
      End
      Begin VB.Label lblTaxLegend 
         Caption         =   "Tax:"
         Height          =   375
         Left            =   600
         TabIndex        =   8
         Top             =   960
         Width           =   735
      End
      Begin VB.Label lblSubtotalLegend 
         Caption         =   "Subtotal:"
         Height          =   255
         Left            =   600
         TabIndex        =   7
         Top             =   480
         Width           =   1095
      End
   End
   Begin VB.Frame fraAddOns 
      Caption         =   "Add-Ons"
      Height          =   2175
      Left            =   120
      TabIndex        =   1
      Top             =   600
      Width           =   3855
      Begin VB.CheckBox chkAddOn 
         Caption         =   "Check1"
         Height          =   375
         Index           =   2
         Left            =   600
         TabIndex        =   5
         Top             =   1560
         Width           =   3135
      End
      Begin VB.CheckBox chkAddOn 
         Caption         =   "Check1"
         Height          =   375
         Index           =   1
         Left            =   600
         TabIndex        =   4
         Top             =   960
         Width           =   3135
      End
      Begin VB.CheckBox chkAddOn 
         Caption         =   "Check1"
         Height          =   375
         Index           =   0
         Left            =   600
         TabIndex        =   3
         Top             =   360
         Width           =   3135
      End
   End
   Begin VB.ComboBox cboMainCourse 
      Height          =   315
      ItemData        =   "frmProj33.frx":0000
      Left            =   1440
      List            =   "frmProj33.frx":0002
      TabIndex        =   0
      Text            =   "Combo1"
      Top             =   150
      Width           =   2415
   End
   Begin VB.Label lblMainCourse 
      Caption         =   "Main Course:"
      Height          =   375
      Left            =   240
      TabIndex        =   2
      Top             =   180
      Width           =   1215
   End
End
Attribute VB_Name = "frmProj33"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Const NAME_POS = 0
Const ADDON_PRICE_POS = 1
Const MAIN_PRICE_POS = 2
Const ADDON_ARRAY_POS = 3

Const TAX_RATE = 0.0785

Dim Products(2, 3) As Variant
Dim HamburgerAddOns(2) As String
Dim PizzaAddOns(2) As String
Dim SaladAddOns(2) As String

Private Sub Form_Load()
    InitArrays
    InitCboMainCourse
    ResetForm
End Sub

Private Sub InitArrays()
    Products(0, NAME_POS) = "Hamburger"
    Products(1, NAME_POS) = "Pizza"
    Products(2, NAME_POS) = "Salad"
    
    Products(0, ADDON_PRICE_POS) = CCur(0.75)
    Products(1, ADDON_PRICE_POS) = CCur(0.5)
    Products(2, ADDON_PRICE_POS) = CCur(0.25)
    
    Products(0, MAIN_PRICE_POS) = CCur(5)
    Products(1, MAIN_PRICE_POS) = CCur(4)
    Products(2, MAIN_PRICE_POS) = CCur(3)
    
    HamburgerAddOns(0) = "Lettuce, Tomato, and Onions"
    HamburgerAddOns(1) = "Mayonnaise and Mustard"
    HamburgerAddOns(2) = "French fries"
    Products(0, ADDON_ARRAY_POS) = HamburgerAddOns
    
    PizzaAddOns(0) = "Pepperoni"
    PizzaAddOns(1) = "Sausage"
    PizzaAddOns(2) = "Olives"
    Products(1, ADDON_ARRAY_POS) = PizzaAddOns
    
    SaladAddOns(0) = "Pepperoni"
    SaladAddOns(1) = "Sausage"
    SaladAddOns(2) = "Olives"
    Products(2, ADDON_ARRAY_POS) = SaladAddOns
End Sub

Private Sub InitCboMainCourse()
    Dim i As Integer
    
    For i = LBound(Products, 1) To UBound(Products, 1)
        cboMainCourse.AddItem Products(i, NAME_POS)
    Next
End Sub

Private Sub ResetForm()
    cboMainCourse.ListIndex = 0
    cmdPrintReceipt.Enabled = False
End Sub

Private Sub cboMainCourse_Click()
    Dim i As Integer
    
    cmdPrintReceipt.Enabled = False
    
    For i = chkAddOn.LBound To chkAddOn.UBound
        chkAddOn(i).Value = vbUnchecked
        chkAddOn(i).Caption = Products(cboMainCourse.ListIndex, ADDON_ARRAY_POS)(i)
    Next
End Sub

Private Sub cmdPlaceOrder_Click()
    DisplayReceipt
    cmdPrintReceipt.Enabled = True
End Sub

Private Sub cmdPrintReceipt_Click()
    Me.PrintForm
    ResetForm
End Sub

Private Sub cmdExit_Click()
    Unload Me
End Sub

Private Sub DisplayReceipt()
    Dim curSubTotal As Currency
    Dim curTax As Currency
    Dim intAddOnCount As Integer
    Dim i As Integer
    Dim intSelectedProduct As Integer
    
    intSelectedProduct = cboMainCourse.ListIndex
    
    For i = chkAddOn.LBound To chkAddOn.UBound
        If chkAddOn(i).Value = vbChecked Then
            intAddOnCount = intAddOnCount + 1
        End If
    Next
    
    curSubTotal = CCur(Products(cboMainCourse.ListIndex, MAIN_PRICE_POS) _
     + intAddOnCount * Products(intSelectedProduct, ADDON_PRICE_POS))
     
    curTax = curSubTotal * TAX_RATE
        
    lblSubtotal.Caption = CStr(FormatCurrency(curSubTotal, 2))
    lblTax.Caption = CStr(FormatCurrency(curTax, 2))
    lblTotal.Caption = CStr(FormatCurrency(curSubTotal + curTax, 2))
End Sub
======================== SNIP HERE (frmProj33.frm) ========================

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy