Answer to Question #268198 in Visual Basic for xxx

Question #268198

Write a VB program to calculate the wages based on different rates (Normal hours and Overtime rates).


Write a FUNCTION to calculate the wages based on the following condition:

-Normal Hours: RM 10 per hours

-Overtime: RM 15 per hours


NOTE: The function should pass in a value of hours as Double, and a value of type as String. The function should return the calculated amount of wages and return as a Double.


*set the Enabled properties of the Total Wages Text Box to False


Example

NormalHours: XXX

OverTime: XXX


Button


Wages: XXX



1
Expert's answer
2021-11-18T08:33:37-0500
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class frmCalculateWages
    Inherits System.Windows.Forms.Form


    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub


    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer


    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.btnCalculate = New System.Windows.Forms.Button()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.txtNormalHours = New System.Windows.Forms.TextBox()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.txtTotalWages = New System.Windows.Forms.TextBox()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.txtOvertime = New System.Windows.Forms.TextBox()
        Me.SuspendLayout()
        '
        'btnCalculate
        '
        Me.btnCalculate.Location = New System.Drawing.Point(107, 70)
        Me.btnCalculate.Name = "btnCalculate"
        Me.btnCalculate.Size = New System.Drawing.Size(100, 25)
        Me.btnCalculate.TabIndex = 0
        Me.btnCalculate.Text = "Calculate"
        Me.btnCalculate.UseVisualStyleBackColor = True
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.Location = New System.Drawing.Point(14, 21)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(72, 13)
        Me.Label1.TabIndex = 1
        Me.Label1.Text = "Normal hours:"
        '
        'txtNormalHours
        '
        Me.txtNormalHours.Location = New System.Drawing.Point(107, 18)
        Me.txtNormalHours.Name = "txtNormalHours"
        Me.txtNormalHours.Size = New System.Drawing.Size(100, 20)
        Me.txtNormalHours.TabIndex = 2
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.Location = New System.Drawing.Point(14, 104)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(71, 13)
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "Total Wages:"
        '
        'txtTotalWages
        '
        Me.txtTotalWages.Enabled = False
        Me.txtTotalWages.Location = New System.Drawing.Point(107, 101)
        Me.txtTotalWages.Name = "txtTotalWages"
        Me.txtTotalWages.Size = New System.Drawing.Size(100, 20)
        Me.txtTotalWages.TabIndex = 2
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.Location = New System.Drawing.Point(14, 47)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(52, 13)
        Me.Label3.TabIndex = 1
        Me.Label3.Text = "Overtime:"
        '
        'txtOvertime
        '
        Me.txtOvertime.Location = New System.Drawing.Point(107, 44)
        Me.txtOvertime.Name = "txtOvertime"
        Me.txtOvertime.Size = New System.Drawing.Size(100, 20)
        Me.txtOvertime.TabIndex = 2
        '
        'frmCalculateWages
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(224, 142)
        Me.Controls.Add(Me.txtTotalWages)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.txtOvertime)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.txtNormalHours)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.btnCalculate)
        Me.Name = "frmCalculateWages"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Calculate wages"
        Me.ResumeLayout(False)
        Me.PerformLayout()


    End Sub
    Friend WithEvents btnCalculate As System.Windows.Forms.Button
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents txtNormalHours As System.Windows.Forms.TextBox
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents txtTotalWages As System.Windows.Forms.TextBox
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents txtOvertime As System.Windows.Forms.TextBox


End Class







Public Class frmCalculateWages
    ''' <summary>
    ''' Write a FUNCTION to calculate the wages based on the following condition:
    ''' -Normal Hours: RM 10 per hours
    ''' -Overtime: RM 15 per hours
    ''' </summary>
    ''' <param name="hours"></param>
    ''' <param name="type"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function calculateWages(ByVal hours As Double, ByVal type As String) As Double
        If (type = "Normal Hours") Then
            Return 10 * hours
        End If
        Return 15 * hours
    End Function


    Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click

        Dim normalHours As Double
        Dim overtimeRates As Double
        Double.TryParse(txtNormalHours.Text, normalHours)
        Double.TryParse(txtOvertime.Text, overtimeRates)
        Dim total As Double = calculateWages(normalHours, "Normal Hours") + calculateWages(overtimeRates, "Overtime rates")
        txtTotalWages.Text = total.ToString("C")


    End Sub
End Class






Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS