All Chapter Exercise of VB
All Chapter Exercise of VB
All Chapter Exercise of VB
'D. Bock
'Today's Date
'Illustrates displaying information to read-only TextBox
'controls by clicking Button controls
End Class
End of Notes.
'Project: Ch02VBUniversity
'D. Bock
'Today's Date
'Module-level variables/constants
Private GrayBackGroundColor As Color
End Class
'Project: Ch03VBUniversity
'D. Bock
'Today's Date
Option Strict On
'Declare variables
Dim SubtotalDecimal, SalesTaxDecimal, TotalDueDecimal
As Decimal
Catch ex As Exception
MessageBox.Show("Error in either Book Price or
Quantity Purchased", "Data Entry Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
PriceTextBox.Focus()
End Try
End Sub
'Enable/disable buttons
ComputeButton.Enabled = True
ResetButton.Enabled = False
End Class
'Project: Ch04VBUniversity (Solution)
'D. Bock
'Today's Date
'Benefit constants
Const MEDICAL_RATE_DECIMAL As Decimal = 35.75D
Const LIFE_RATE_DECIMAL As Decimal = 18.35D
Const DENTAL_RATE_DECIMAL As Decimal = 4D
End Class
'Project: Ch04VBUniversity (Solution)
'D. Bock
'Today's Date
'Benefit constants
Const MEDICAL_RATE_DECIMAL As Decimal = 35.75D
Const LIFE_RATE_DECIMAL As Decimal = 18.35D
Const DENTAL_RATE_DECIMAL As Decimal = 4D
End Class
'Project: Ch05VBUniversity (Solution)
'D. Bock
'Today's Date
Option Strict On
#End Region
#End Region
#End Region
#End Region
'Return a value
Return FederalTaxDecimal
End Function
#End Region
End Class
This solution shows the Ch07VBUniversity project code.
Option Strict On
DepartmentComboBox.Items.Add(DepartmentComboBox.Text.Trim)
Else
MessageBox.Show("Duplicate or Invalid Department
Name", "Duplicate Data Error", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation)
DepartmentComboBox.Focus()
DepartmentComboBox.SelectAll()
End If
End Sub
MessageBox.Show(EmployeeListBox.SelectedItem.ToString, "Current
selection", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
DepartmentComboBox.Items.Remove(DepartmentComboBox.SelectedItem)
'This next line of code clears the Text
'property of the ComboBox – this is automatic
'for the Remove method, but not for the last
'item in a list.
DepartmentComboBox.Text = String.Empty
End If
End Sub
Private Sub RemoveAtDepartmentToolStripMenuItem_Click(ByVal
sender As System.Object, ByVal e As System.EventArgs) Handles
RemoveAtDepartmentToolStripMenuItem.Click
'Try to remove the department if one is selected
Try
'Declare dialog result variable
Dim ResponseDialogResult As DialogResult =
MessageBox.Show("Remove the selected department?", "Remove ?",
MessageBoxButtons.YesNo, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2)
If ResponseDialogResult =
Windows.Forms.DialogResult.Yes Then
'Remove the selected department from the listing
DepartmentComboBox.Items.RemoveAt(DepartmentComboBox.SelectedInde
x)
'This next line of code clears the Text
'property of the ComboBox – this is automatic
'for the Remove method, but not for the last
'item in a list.
DepartmentComboBox.Text = String.Empty
End If
Catch ex As ArgumentOutOfRangeException
MessageBox.Show("You must select a department to
remove.", "No Selection Was Made", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Else
'Data passes all business rules
ValidData = True
End If
End Function
Option Strict On
'Module-level declarations
Private NumberProductsInteger As Integer = 7 'number of products
'Array of type Product
Private InventoryProduct(NumberProductsInteger) As Product
Private TotalDueDecimal As Decimal 'total amount for individual customer
InventoryProduct(1).ProductIDString = "A804"
InventoryProduct(1).DescriptionString = "College Logo Tshirt"
InventoryProduct(1).QuantityInteger = 15
InventoryProduct(1).PriceDecimal = 18.99D
InventoryProduct(2).ProductIDString = "C344"
InventoryProduct(2).DescriptionString = "College Logo Sweat Pants"
InventoryProduct(2).QuantityInteger = 25
InventoryProduct(2).PriceDecimal = 25.99D
InventoryProduct(3).ProductIDString = "F554"
InventoryProduct(3).DescriptionString = "Drinking Mug"
InventoryProduct(3).QuantityInteger = 8
InventoryProduct(3).PriceDecimal = 5.49D
InventoryProduct(4).ProductIDString = "G302"
InventoryProduct(4).DescriptionString = "Pencil and Pen Set"
InventoryProduct(4).QuantityInteger = 15
InventoryProduct(4).PriceDecimal = 35.5D
InventoryProduct(5).ProductIDString = "M302"
InventoryProduct(5).DescriptionString = "College Logo Sweat Shirt"
InventoryProduct(5).QuantityInteger = 25
InventoryProduct(5).PriceDecimal = 22.99D
InventoryProduct(6).ProductIDString = "S499"
InventoryProduct(6).DescriptionString = "Intro to Philosophy Textbook"
InventoryProduct(6).QuantityInteger = 50
InventoryProduct(6).PriceDecimal = 85D
InventoryProduct(7).ProductIDString = "X599"
InventoryProduct(7).DescriptionString = "Intro to CMIS Textbook"
InventoryProduct(7).QuantityInteger = 75
InventoryProduct(7).PriceDecimal = 79.4D
End Sub
'Here you can clear the form of product info if you think
'that is a good way to do the processing
ProductIDTextBox.Clear()
DescriptionTextBox.Clear()
PriceTextBox.Clear()
QuantityTextBox.Clear()
ProductIDTextBox.Focus()
End If
End Sub
End Class
Option Strict On
InventoryProduct(1).ProductIDString = "A804"
InventoryProduct(1).DescriptionString = "College Logo Tshirt"
InventoryProduct(1).QuantityInteger = 15
InventoryProduct(1).PriceDecimal = 18.99D
InventoryProduct(2).ProductIDString = "C344"
InventoryProduct(2).DescriptionString = "College Logo Sweat Pants"
InventoryProduct(2).QuantityInteger = 25
InventoryProduct(2).PriceDecimal = 25.99D
InventoryProduct(3).ProductIDString = "F554"
InventoryProduct(3).DescriptionString = "Drinking Mug"
InventoryProduct(3).QuantityInteger = 8
InventoryProduct(3).PriceDecimal = 5.49D
InventoryProduct(4).ProductIDString = "G302"
InventoryProduct(4).DescriptionString = "Pencil and Pen Set"
InventoryProduct(4).QuantityInteger = 15
InventoryProduct(4).PriceDecimal = 35.5D
InventoryProduct(5).ProductIDString = "M302"
InventoryProduct(5).DescriptionString = "College Logo Sweat Shirt"
InventoryProduct(5).QuantityInteger = 25
InventoryProduct(5).PriceDecimal = 22.99D
InventoryProduct(6).ProductIDString = "S499"
InventoryProduct(6).DescriptionString = "Intro to Philosophy Textbook"
InventoryProduct(6).QuantityInteger = 50
InventoryProduct(6).PriceDecimal = 85D
InventoryProduct(7).ProductIDString = "X599"
InventoryProduct(7).DescriptionString = "Intro to CMIS Textbook"
InventoryProduct(7).QuantityInteger = 75
InventoryProduct(7).PriceDecimal = 79.4D
End Sub
'Here you can clear the form of product info if you think
'that is a good way to do the processing
ProductIDComboBox.SelectedIndex = -1
ProductIDTextBox.Clear()
DescriptionTextBox.Clear()
PriceTextBox.Clear()
QuantityTextBox.Clear()
ProductIDTextBox.Focus()
End If
End Sub
'Increment RowInteger
RowInteger += 1
Next
End Class
Option Strict On
'Module-level declarations
Private NumberProductsInteger As Integer = 7 'number of products
Private TotalDueDecimal As Decimal 'total amount for individual customer
'Here you can clear the form of product info if you think
'that is a good way to do the processing
ProductIDTextBox.Clear()
DescriptionTextBox.Clear()
PriceTextBox.Clear()
QuantityTextBox.Clear()
ProductIDTextBox.Focus()
Else
MessageBox.Show("Ask for a raincheck, we are out of that
product.", "Out of Stock", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
End If
End Sub
End class
'D. Bock
'Today's Date
Option Strict On
Public Class StudentDetails
Try
If ValidData() Then
'Me.Validate()
Me.StudentBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.StudentDetailsDataSet)
Me.SetControls(True)
End If
Catch ex As Exception
End Try
End Sub
Try
Me.StatesTableAdapter.Fill(Me.StatesDataSet.States)
Me.StudentTableAdapter.Fill(Me.StudentDetailsDataSet.Student)
Catch ex As Exception
End Try
End Sub
'operations
SSNMaskedTextBox.ReadOnly = ValueBoolean
LastNameTextBox.ReadOnly = ValueBoolean
FirstNameTextBox.ReadOnly = ValueBoolean
MiddleInitialTextBox.ReadOnly = ValueBoolean
AddressTextBox.ReadOnly = ValueBoolean
CityTextBox.ReadOnly = ValueBoolean
ZipMaskedTextBox.ReadOnly = ValueBoolean
PhoneMaskedTextBox.ReadOnly = ValueBoolean
EmailAddressTextBox.ReadOnly = ValueBoolean
MajorTextBox.ReadOnly = ValueBoolean
AccountBalanceTextBox.ReadOnly = ValueBoolean
'StateCodeTextBox.ReadOnly = ValueBoolean
BindingNavigatorMoveFirstItem.Visible = ValueBoolean
BindingNavigatorMoveLastItem.Visible = ValueBoolean
BindingNavigatorMoveNextItem.Visible = ValueBoolean
BindingNavigatorMovePreviousItem.Visible = ValueBoolean
BindingNavigatorPositionItem.Visible = ValueBoolean
BindingNavigatorCountItem.Visible = ValueBoolean
BindingNavigatorAddNewItem.Visible = ValueBoolean
BindingNavigatorDeleteItem.Visible = ValueBoolean
EditToolStripButton.Visible = ValueBoolean
'Enable/disable ComboBox
LastNameComboBox.Enabled = ValueBoolean
End Sub
End Sub
StudentBindingSource.CancelEdit()
SetControls(True)
End Sub
SetControls(False)
'Set focus
SSNMaskedTextBox.Focus()
End Sub
StudentBindingSource.RemoveCurrent()
StudentBindingSource.EndEdit()
TableAdapterManager.UpdateAll(StudentDetailsDataSet)
End If
StudentDetailsDataSet.RejectChanges()
StudentBindingSource.Position = RowNumberInteger
Catch ex As Exception
'Some other exception was triggered
End Try
End Sub
ValidData = False
SSNMaskedTextBox.Focus()
SSNMaskedTextBox.SelectAll()
LastNameTextBox.Focus()
LastNameTextBox.SelectAll()
FirstNameTextBox.Focus()
FirstNameTextBox.SelectAll()
'Validate Address
AddressTextBox.Focus()
AddressTextBox.SelectAll()
'Validate City
CityTextBox.Focus()
CityTextBox.SelectAll()
'Validate State
StateComboBox.Focus()
ZipMaskedTextBox.Focus()
ZipMaskedTextBox.SelectAll()
AccountBalanceTextBox.Focus()
AccountBalanceTextBox.SelectAll()
Else
ValidData = True
End If
End Function
Case Else
End Select
End Sub
End Class