audio_uphoria
Active member
- Joined
- Jan 28, 2009
- Messages
- 31
- Programming Experience
- Beginner
Hello, I had an assignment where I'm supposed to use two sub procedures. Now I'm supposed to do the same program but using two functions. The subs were very easy and straight forward but I cant get functions to work no matter what I do. Here's my code for the assignment with the subs, going off that can you help me with the functions. The functions are supposed to replace the subs.
VB.NET:
Option Explicit On
Option Strict On
Public Class frmMain
Dim Input As Integer
Dim Output As Double
Private Sub btnConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConvert.Click
Integer.TryParse(txtInput.Text, Input)
If rdoToF.Checked = False And rdoToC.Checked = False _
Or txtInput.Text = "" Then
MessageBox.Show("Please specify what you want to convert to", "Error Message")
txtInput.Focus()
ElseIf rdoToC.Checked = True Then
Call ConvertToCelsius()
lblOutPut.Text = Output.ToString("n1")
ElseIf rdoToF.Checked = True Then
Call ConvertToFar()
lblOutPut.Text = Output.ToString("n1")
End If
End Sub
Private Sub ConvertToCelsius()
Output = (5 / 9) * (Input - 32)
End Sub
Private Sub ConvertToFar()
Output = (9 / 5) * Input + 32
End Sub
Private Sub txtInput_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtInput.Enter
txtInput.SelectAll()
End Sub
Private Sub rdoToC_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles rdoToC.Click
If rdoToC.Checked = True Then
lblOutPut.Text = ""
lblDegreeIn.Text = "F"
lblDegreeOut.Text = "C"
txtInput.Focus()
End If
End Sub
Private Sub rdoToF_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles rdoToF.Click
If rdoToF.Checked = True Then
lblOutPut.Text = ""
lblDegreeIn.Text = "C"
lblDegreeOut.Text = "F"
txtInput.Focus()
End If
End Sub
Private Sub txtInput_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtInput.TextChanged
lblOutPut.Text = ""
End Sub
Private Sub frmMain_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Leave, btnExit.Click
Me.Close()
End Sub
End Class