Room Charges Calculator Program using VB.Net

In our previous tutorial we focused in visual basic 6.0 by creating the point of sales, this time we are going to build a simple room charges calculator to calculate the charges of a hotel room using Microsoft Visual Basic .NET.

Things we need:
Microsoft Visual Basic .NET 2013 or later

Step 1: Open your Microsoft Visual Studio, Click New Project then in the Installed Templates go to Visual Basic and Click Windows, After that in the Name textfield which is the name of your Windows Application Project put prjHotel, in the Location textfield you can browse any directory to save your files.



Step 2: If you don’t have a form, add one first then put the following control objects:


(PLEASE REFER TO THE IMAGE ABOVE)  

FORM PROPERTIES
StartPosition: CenterScreen
Text: Room Charge Calculator

Add FOUR LABELS:

1st LABEL PROPERTIES
Text: Rancher’s Hotel
Font: Tahoma, 26.25pt, style=Bold
Backcolor: MenuHighlight

2nd 3rd LABEL PROPERTIES
Text: Date: , Time:
Font: Microsoft Sans Serif, 9.75pt

4th 5th LABEL PROPERTIES
Text: empty
Font: Microsoft Sans Serif, 9.75pt
BorderStyle: Fixed3D

Add THREE GROUPBOX

1st 2nd 3rd GROUPBOX
Text: Room Information, Additional Charges, TOTAL CHARGES
Font: Microsoft Sans Serif, 9.75PT, style=Bold

Add TWO LABELS and TWO TEXTBOX inside the room information GROUPBOX

1st 2nd LABEL PROPERTIES
Text: No. Of Nights, Rate Per Night
Font: Microsoft Sans Serif, 8.25PT

1st 2nd TEXTBOX PROPERTIES
(Name): txtNyt, txtRate
Text: 0, 0
Font: Microsoft Sans Serif, 9.75PT, style=Bold

Add THREE LABELS and THREE TEXTBOX inside the additional charges GROUPBOX

1st 2nd 3rd LABEL PROPERTIES
Text: Room Service, Telephone, Miscellaneous
Font: Microsoft Sans Serif, 8.25PT

1st 2nd 3rd TEXTBOX PROPERTIES
(Name): txtRoom, txtTel, txtMisc
Text: 0, 0, 0
Font: Microsoft Sans Serif, 9.75PT, style=Bold

Add EIGHT LABELS inside the total charges GROUPBOX

1st 2nd 3rd 4th LABEL PROPERTIES
Text: ROOM CHARGES, ADDITIONAL CHARGES, SUB TOTAL, TAX
Font: Microsoft Sans Serif, 9.75PT

5th 6th 7th 8th LABEL PROPERTIES  
Text: leave the text properties empty
(Name): lblRoom, lblCharges, lblSub, lblTax
Font: Microsoft Sans Serif, 9.75PT

9th LABEL PROPERTIES
Text: TOTAL CHARGES
Font: Microsoft Sans Serif, 12pt, style=Bold

10th LABEL PROPERTIES
Text: leave the text properties empty
(Name): lblTotal
Font: Microsoft Sans Serif, 12pt, style=Bold

Add THREE BUTTONS on the form

1st 2nd 3rd BUTTON PROPERTIES
(Name): btnCal, btnClear, btnExit
Text: CALCULATE, CLEAR, EXIT
Font: Tahoma, 9.75pt, style=Bold

Add TIMER on the form

TIMER PROPERTIES
Enabled: True
Interval: 1000

Go to your Code Editor and Paste this code. 

Option Strict On

Public Class Form1

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        lblDate.Text = Now.ToString("D")
        lblTime.Text = Now.ToString("T")

    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b.Click
        Me.Close()
    End Sub

    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        txtNyt.Clear()
        txtRate.Clear()
        txtRoom.Clear()
        txtTel.Clear()
        txtMisc.Clear()

        lblRoom.Text = Nothing
        lblCharges.Text = ""
        lblSub.Text = String.Empty
        lblTax.Text = Nothing
        lblTotal.Text = Nothing
        txtRoom.Focus()
    End Sub

    Private Sub btnCal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCal.Click
        Dim nyt As Integer = 0
        Dim nytcharge As Decimal = 0
        Dim roomServ As Decimal = 0
        Dim Tel As Decimal = 0
        Dim Misc As Decimal = 0
        Dim TaxRate As Decimal = 0.0925D

        Dim charges, Add, subTotal, Tax, Total As Decimal

        Try
            nyt = CInt(txtNyt.Text)
            nytcharge = CDec(txtRate.Text)
            roomServ = CDec(txtRoom.Text)
            Tel = CDec(txtTel.Text)
            Misc = CDec(txtMisc.Text)
        Catch ex As Exception
            MessageBox.Show("Invalid Input, Please enter numeric value")
            txtNyt.SelectAll()
            txtNyt.Focus()
            Exit Sub
        End Try

        charges = nyt * nytcharge
        Add = roomServ + Misc + Tel
        subTotal = charges + Add
        Tax = subTotal * TaxRate
        Total = subTotal + Tax

        lblRoom.Text = charges.ToString("C")
        lblCharges.Text = Add.ToString("C")
        lblSub.Text = subTotal.ToString("C")
        lblTax.Text = Tax.ToString("C")
        lblTotal.Text = Total.ToString("C")
    End Sub
End Class

FINAL OUTPUT:


Room Charges Calculator Program using VB.Net Room Charges Calculator Program using VB.Net Reviewed by code-dev on 10:39 PM Rating: 5

1 comment:

Powered by Blogger.