The purpose of this project is to create a VBA program, activated by an Activex
ID: 3738998 • Letter: T
Question
The purpose of this project is to create a VBA program, activated by an Activex command button, which will convert between all four temperature units: degrees Celsius, degrees Fahrenheit, Kelvins, and degrees Rankine. When the user clicks the command button, the following steps need to occur: The user should be given two input box for the value and units of the temperature that is to be converted. If invalid units are box, and entered, the user should be informed using a message then the units input box should be given to the user again. 'Based on the units of the temperature to be converted, the program should choose an appropriate input box to give the user for the desired temperature units. If invalid units are entered, the user should be informed using a message box, and then the desired units input box should be given to the user again. Also based on the units of the temperature to be converted, the program should call a sub procedure that will convert the current units into any of the other units. That is, there will be four sub procedures, one each to convert from C, F, K, and ° Once a sub procedure has finished its job, the main program should use a message box to give the user the temperature conversion in the form 0 C 32 F. Even though the unit K does not use a symbol, it is okay to use one so that only one message box statement is needed to give the user the temperature conversion. * Finally, the user should be asked, using a message box, if s/he another temperature. If the user answers again. yes, the first input box should be given to the userExplanation / Answer
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
compare()
MessageBox.Show(Label6.Text)
txtconvert.Text = ""
Label5.Visible = False
txtconvert.Visible = False
Button1.Visible = False
txtvalue.Text = ""
txtunit.Text = ""
Label6.Text = ""
End Sub
Sub compare()
Dim feh, cel, kel, rank As Double
Dim temp As String
temp = txtunit.Text
Select Case temp
Case "C"
If txtconvert.Text = "F" Then
Label6.Text = txtvalue.Text & " Celsius = " & (txtvalue.Text * 1.8) + 32 & " Fahrenheit"
ElseIf txtconvert.Text = "K" Then
Label6.Text = txtvalue.Text & " Celsius = " & (txtvalue.Text) + 273.15 & " Kelvin"
ElseIf txtconvert.Text = "R" Then
feh = (txtvalue.Text * 1.8) + 32
Label6.Text = txtvalue.Text & " Celsius = " & (feh + 459.67) & " Rankine"
ElseIf txtconvert.Text = "C" Then
Label6.Text = txtvalue.Text & " Celsius = " & (txtvalue.Text) & " Celsius"
Else
MessageBox.Show("Invalid Input")
End If
Case "F"
If txtconvert.Text = "C" Then
Label6.Text = txtvalue.Text & " Fahrenheit = " & (txtvalue.Text - 32) * 0.555 & " Celsius"
ElseIf txtconvert.Text = "K" Then
cel = (txtvalue.Text - 32) * 0.555
Label6.Text = txtvalue.Text & " Fahrenheit = " & (cel) + 273.15 & " Kelvin"
ElseIf txtconvert.Text = "R" Then
Label6.Text = txtvalue.Text & " Fahrenheit = " & (txtvalue.Text + 459.67) & " Rankine"
ElseIf txtconvert.Text = "F" Then
Label6.Text = txtvalue.Text & " Fahrenheit = " & (txtvalue.Text) & " Fahrenheit"
Else
MessageBox.Show("Invalid Input")
End If
Case "K"
If txtconvert.Text = "C" Then
Label6.Text = txtvalue.Text & " Kelvin = " & (txtvalue.Text - 273.15) & " Celsius"
ElseIf txtconvert.Text = "F" Then
cel = (txtvalue.Text - 273.15)
Label6.Text = txtvalue.Text & " Kelvin = " & (1.8 * cel) + 32 & " Fahrenheit"
ElseIf txtconvert.Text = "R" Then
cel = (txtvalue.Text - 273.15)
feh = (1.8 * cel) + 32
Label6.Text = txtvalue.Text & " Kelvin = " & (feh + 459.67) & " Rankine"
ElseIf txtconvert.Text = "K" Then
Label6.Text = txtvalue.Text & " Kelvin = " & (txtvalue.Text) & " Kelvin"
Else
MessageBox.Show("Invalid Input")
End If
Case "R"
feh = (txtvalue.Text - 459.67)
cel = 0.555 * (feh - 32)
If txtconvert.Text = "C" Then
Label6.Text = txtvalue.Text & " Rankine = " & cel & " Celsius"
ElseIf txtconvert.Text = "F" Then
Label6.Text = txtvalue.Text & " Rankine = " & (txtvalue.Text - 459.67) & " Fahrenheit"
ElseIf txtconvert.Text = "K" Then
Label6.Text = txtvalue.Text & " Rankine = " & (cel + 273.15) & " Kelvin"
ElseIf txtconvert.Text = "R" Then
Label6.Text = txtvalue.Text & " Rankine = " & (txtvalue.Text) & " Rankine"
Else
MessageBox.Show("Invalid Input")
End If
Case Else
MessageBox.Show("Invalid Input")
End Select
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If txtunit.Text = "C" OrElse txtunit.Text = "F" OrElse txtunit.Text = "K" OrElse txtunit.Text = "R" Then
If IsNumeric(txtvalue.Text) Then
Label5.Visible = True
txtconvert.Visible = True
Button1.Visible = True
Else
MessageBox.Show("Invalid Input")
End If
Else
MessageBox.Show("Invalid Input")
End If
End Sub
End Class
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.