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) ======================== |