

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Ifs AND MENUs Option Strict On Public Class frmCampground Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click ' Calculate rental cost Dim intNumberNights As Integer Dim decCostPerNight As Decimal ' No data validation ' take what user entered and place in variable intNumberNights = Convert.ToInt32(txtNumberNights.Text) ' determine the cost per night based on the cbo choice If cboCampSite.SelectedIndex = 0 Then ' 0 would be the first item, tent site decCostPerNight = 20 ElseIf cboCampSite.SelectedIndex = 1 Then ' 1 would be the next which is RV decCostPerNight = 35 Else ' the last one is cabin decCostPerNight = 50 End If ' 0r use the text in the combo box: 'If cboCampSite.SelectedText = "tent site" Then ' decCostPerNight = 20 'ElseIf cboCampSite.SelectedText = "RV" Then ' decCostPerNight = 35 'Else ' decCostPerNight = 50 'End If Dim decTotal As Decimal decTotal = intNumberNights * decCostPerNight ' check boxes can all be selected unlike radio buttons. So each checkbox if statement must have an endif If chkAAADiscount.Checked Then decTotal *= 0.9D End If If chkMilitaryDiscount.Checked Then decTotal *= 0.85D End If ' return the value of decTotal formatted as currency to the call of the function lblTotal.Text = decTotal.ToString("C") End Sub Private Sub mnuFileExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileExit.Click Close() End Sub
Private Sub mnuFileReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileReset.Click txtNumberNights.Clear() cboCampSite.SelectedIndex = - chkAAADiscount.Checked = False chkMilitaryDiscount.Checked = False lblTotal.Text = "" End Sub End Class LOOP Option Strict On Public Class frmLoop Private Sub btnMultiply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMultiply.Click Dim intCount As Integer Dim intNumber As Integer Dim decProduct As Decimal 'no validation 'assign the user's choice to intNumber intNumber = Convert.ToInt16(cboNumber.SelectedItem) ' loop for intcount is 10 down to 0 so decrement the counter on each iteration For intCount = 10 To 0 Step - decProduct = intCount * intNumber ' display the times table line in the list lstMultiply.Items.Add(intNumber & " X " & intCount & " = " & decProduct) Next End Sub Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click cboNumber.SelectedIndex = - lstMultiply.Items.Clear() End Sub End Class