Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'Made by Junkie
- '10/13/2013
- Option Strict On
- Public Class frmRentList
- #Region "Constant Declarations"
- Private Const FLOOR_NUM_MIN As Integer = 3
- Private Const FLOOR_NUM_MAX As Integer = 20
- Private Const RENT_LOWER_LIMIT As Integer = 1000
- Private Const RENT_UPPER_LIMIT As Integer = 2500
- #End Region
- #Region "Form Level Variable Declarations"
- Private numFloors As Integer
- Private requestedFloor As Integer
- Private rentList() As Integer
- #End Region
- #Region "Validating Event Handlers"
- 'here we are validating the text boxes for name and the number of floors
- Private Sub NameValidatingEvent(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles _
- txtName.Validating,
- txtNumFloors.Validating
- Dim txtbox As TextBox = CType(sender, TextBox)
- Dim datadescription As String = String.Empty
- If sender Is txtName Then
- datadescription = "Name"
- ElseIf sender Is txtNumFloors Then
- datadescription = "Number of Floors"
- End If
- e.Cancel = ValidateStringInput(datadescription, txtbox.Text)
- End Sub
- Private Sub NumberValidatingEvent(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles _
- txtNumFloors.Validating
- Const FLOORS_LOWER_LIMIT As Integer = 3
- Const FLOORS_UPPER_LIMIT As Integer = 20
- Dim txtBox As TextBox = CType(sender, TextBox)
- If sender Is txtNumFloors Then
- e.Cancel = ValidateNumberInput("Number of Floors", txtBox.Text, FLOORS_LOWER_LIMIT, FLOORS_UPPER_LIMIT, numFloors)
- btnRentList.Enabled = Not (e.Cancel)
- End If
- If e.Cancel Then
- txtBox.Clear()
- End If
- End Sub
- #End Region
- #Region "Utility Modules"
- Private Function ValidateStringInput(ByVal dataDescription As String, ByVal strInput As String) As Boolean
- Dim invalid As Boolean = True
- If Not String.IsNullOrEmpty(strInput) Then
- invalid = False
- Else
- MessageBox.Show(dataDescription & " must be provided", "Empty " & dataDescription, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
- invalid = True
- End If
- Return invalid
- End Function
- Private Function ValidateNumberInput(ByVal dataType As String, ByVal strInput As String, _
- ByVal min As Integer, ByVal max As Integer, _
- ByRef value As Integer) As Boolean
- Dim invalid As Boolean = True
- If IsNumeric(strInput) Then
- value = Integer.Parse(strInput)
- If value >= min AndAlso value <= max Then
- invalid = False
- Else
- MessageBox.Show(dataType & " must be between " & min & " and " & max & "--try again", "Invalid " & dataType, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
- invalid = True
- End If
- Else
- MessageBox.Show(dataType & " must be between " & min & " and " & max & "--try again", "Invalid " & dataType, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
- invalid = True
- End If
- Return invalid
- End Function
- Private Sub ClearFields()
- txtName.Clear()
- txtNumFloors.Clear()
- txtFloorRequest.Clear()
- lstRents.Items.Clear()
- lblRentResults.Visible = False
- btnRentList.Enabled = False
- btnGetFloorRent.Enabled = False
- End Sub
- 'getting the rent data
- Private Sub CollectFloorRentData()
- lstRents.Items.Add("Floor" & vbTab & "Rent")
- If numFloors > 0 Then
- ReDim rentList(numFloors - 1)
- For i As Integer = 0 To rentList.Count - 1
- rentList(i) = GetData("Floor Rent: ", RENT_LOWER_LIMIT, RENT_UPPER_LIMIT)
- addtodisplaylist(i + 1, rentList(i))
- Next
- End If
- End Sub
- 'displaying the floor numbers and rent for each floor
- Private Sub addtodisplaylist(ByVal numfloors As Integer, ByVal rentlist As Integer)
- lstRents.Items.Add(numfloors.ToString & vbTab _
- & rentlist.ToString)
- End Sub
- Private Function GetData(ByVal dataDescription As String, ByVal lowerLimit As Integer, ByVal upperLimit As Integer) As Integer
- 'getting floor level data
- Dim value As Integer
- Dim response As String
- Do
- response = InputBox("Enter the number of " & dataDescription & "(" & lowerLimit.ToString & " to " & upperLimit.ToString & "): ")
- ValidateNumberInput(dataDescription, response, lowerLimit, upperLimit, value)
- Loop Until (value >= lowerLimit AndAlso value <= upperLimit)
- Return value
- End Function
- 'finding and verifying the user specified floor
- Private Sub findfloordata()
- Dim floorrequest As Integer = CInt(txtFloorRequest.Text)
- If floorrequest <= numFloors Then
- DisplaySummaryData(rentList(floorrequest - 1))
- Else
- MessageBox.Show("Floor request must be between 1 and " & numFloors, "Error" & MessageBoxButtons.OK & MessageBoxIcon.Exclamation)
- End If
- End Sub
- 'this is where the results are displayed in the rent total label
- Private Sub DisplaySummaryData(ByVal rentlist As Integer)
- lblRentResults.Visible = True
- lblRentResults.Text = ("Apartment Name " & txtName.Text & vbNewLine _
- & "Floor Number " & txtFloorRequest.Text & vbNewLine _
- & "Rent " & rentlist)
- End Sub
- #End Region
- Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
- 'exit button
- Me.Close()
- End Sub
- Private Sub frmRentList_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- End Sub
- Private Sub btnRentList_Click(sender As Object, e As EventArgs) Handles btnRentList.Click
- 'displaying rent in the list box
- CollectFloorRentData()
- End Sub
- Private Sub btnGetFloorRent_Click(sender As Object, e As EventArgs) Handles btnGetFloorRent.Click
- 'displaying rent total for given floor
- findfloordata()
- End Sub
- Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
- 'clear button
- Me.lblRentResults.Text = ""
- Me.lstRents.Text = ""
- Me.txtFloorRequest.Text = ""
- Me.txtName.Text = ""
- Me.txtNumFloors.Text = ""
- End Sub
- End Class
Add Comment
Please, Sign In to add comment