Describe what the following program does: Public Class frmWeight Private Sub btn
ID: 3673897 • Letter: D
Question
Describe what the following program does: Public Class frmWeight Private Sub btnDisplay_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles btnDisplay.Click Dim strEnterWeight As String Dim decEnterWeight As Decimal Dim decWeight As Decimal strEnterWeight = txtEnterWeight.Text If IsNumeric(strEnterWeight) Then decEnterWeight = Convert.ToDecimal(strEnterWeight) IfdecEnterWeight > 0 Then If radLbstoKg.Checked Then lblMeasurement.Text = "kilograms" decWeight = decEnterWeight / 2.2 lblWeight.Text = decWeight.ToString("F1") Else lblMeasurement.Text = "pounds" decWeight = decEnterWeight * 2.2 lblWeight.Text = decWeight.ToString("F1") End If End If End If End Sub End Class
Explanation / Answer
# Though not sure which language it is, I wil try to explain what it is.
# Basically this program is trying to convert user entered weight from Kilograms to pounds and vice versa.
# 1. Format the code, (not sure may be you have it already formatted for you, But it took a while for me to format to make it readable).
# 2. It is a class with one sub( sub i something like method).
# 3. Sub has 3 local varibles,
# strEnterWeight is variable of type String.
# decEnterWeight is variable of type Decimal.(numeric)
# decWeight is variable of type Decimal(numeric)
# comments in inline
Public Class frmWeight
Private Sub btnDisplay_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles btnDisplay.Click
Dim strEnterWeight As String
Dim decEnterWeight As Decimal
Dim decWeight As Decimal
# Taking useded data as input.
strEnterWeight = txtEnterWeight.Text
# checking is it number or not. if not number then nothing wil happen.
If IsNumeric(strEnterWeight) Then
decEnterWeight = Convert.ToDecimal(strEnterWeight) # converting string form of weight to decimal
If decEnterWeight > 0 Then # if greater than 0, then it is assumed to be in kilograms and dividing it with 2.2
If radLbstoKg.Checked Then
lblMeasurement.Text = "kilograms"
decWeight = decEnterWeight / 2.2
lblWeight.Text = decWeight.ToString("F1")
Else # if less than 0, then it is assumed to be in pounds and multiplying it with 2.2
lblMeasurement.Text = "pounds"
decWeight = decEnterWeight * 2.2
lblWeight.Text = decWeight.ToString("F1")
End If
End If
End If
End Sub
End Class