| You are here: DEVPPL ‹ Forum ‹ Programming ‹ Visual Basic Forum |
NOTIFICATIONS
|
|
|||||||||||||||
Login |
New member, problems coding
1 post
• Page 1 of 1
0
New member, problems coding
Hello, I am a student and I am taking a distance learning course for VB 2010 and I am having some trouble. I need to make a program that allows the user to select let's say, between two technicians using radio buttons, then once a tech is selected, they will be able to enter the temperature (as many times as they want), hold an average EACH time they enter a new temperature, be able to convert it to Celsius whenever they want, and upon exiting, display the total average temperature, for one of the techs, or BOTH techs in a message box.
Below is my code, it is messed up now. At one point, entering the temperature and converting it worked fine, but since then I have done worse damage. I need a lot of work as you can see. This distance learning is not good for me. I am new to programming and I often have questions, but no one to ask. I appreciate any help.
Public Class Form1
Dim intTemp As Integer
Dim intAver As Integer
Dim Celsius As Single
Const intNUM_DAT As Integer = 5 'Counter for loop
Dim intTotal As Integer = 0 'Accumulator
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
'Get the average scores
'declare a variable of the DialogResult enumeration
Dim dgrResult As DialogResult
'call the btnClear Click event procedure
btnClear.PerformClick()
'capture the user's response to the MessageBox
dgrResult = MessageBox.Show("Are you sure you want to exit?", "Exit?", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
'exit the program if the user verifies that s/he want to exit
If dgrResult = Windows.Forms.DialogResult.Yes Then
Me.Close()
End If
Me.Close()
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
'Reset the Tim Radio Button
radTim.Checked = True
'Uncheck the checkbox
chkCels.Checked = False
'Clear the text boxes
txtTemp.Clear()
'Clear the lables
lblAver.Text = String.Empty
txtCels.Text = String.Empty
'Give the focus to text box
txtTemp.Focus()
End Sub
Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
If intTemp <= intNUM_DAT Then
If String.IsNullOrEmpty(txtTemp.Text) Then
MessageBox.Show("Enter a numeric value.")
'Get the temperature from the user
Else
' Make sure the entry is numeric
If IsNumeric(txtTemp.Text) Then
'Get the temperature from the user
intTemp = CInt(txtTemp.Text)
intTotal += intTemp
intTemp += 1
intAver = CInt(intTotal / intTemp)
lblAver.Text = CStr(intTemp)
Else
MessageBox.Show("Enter a numeric value.")
End If
' Clear the textbox for the next entry
txtTemp.Text = String.Empty
End If
End If
lblAver.Text = intAver.ToString()
End Sub
Private Sub chkCels_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkCels.CheckedChanged
'pull the answer from here
lblAver.Text = CStr(intTemp)
'the conversion formula
Celsius = CSng(Int((intTemp - 32) / 9) * 5)
txtCels.Text = CStr(Celsius)
End Sub
Private Sub lblCels_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
Below is my code, it is messed up now. At one point, entering the temperature and converting it worked fine, but since then I have done worse damage. I need a lot of work as you can see. This distance learning is not good for me. I am new to programming and I often have questions, but no one to ask. I appreciate any help.
Public Class Form1
Dim intTemp As Integer
Dim intAver As Integer
Dim Celsius As Single
Const intNUM_DAT As Integer = 5 'Counter for loop
Dim intTotal As Integer = 0 'Accumulator
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
'Get the average scores
'declare a variable of the DialogResult enumeration
Dim dgrResult As DialogResult
'call the btnClear Click event procedure
btnClear.PerformClick()
'capture the user's response to the MessageBox
dgrResult = MessageBox.Show("Are you sure you want to exit?", "Exit?", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
'exit the program if the user verifies that s/he want to exit
If dgrResult = Windows.Forms.DialogResult.Yes Then
Me.Close()
End If
Me.Close()
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
'Reset the Tim Radio Button
radTim.Checked = True
'Uncheck the checkbox
chkCels.Checked = False
'Clear the text boxes
txtTemp.Clear()
'Clear the lables
lblAver.Text = String.Empty
txtCels.Text = String.Empty
'Give the focus to text box
txtTemp.Focus()
End Sub
Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
If intTemp <= intNUM_DAT Then
If String.IsNullOrEmpty(txtTemp.Text) Then
MessageBox.Show("Enter a numeric value.")
'Get the temperature from the user
Else
' Make sure the entry is numeric
If IsNumeric(txtTemp.Text) Then
'Get the temperature from the user
intTemp = CInt(txtTemp.Text)
intTotal += intTemp
intTemp += 1
intAver = CInt(intTotal / intTemp)
lblAver.Text = CStr(intTemp)
Else
MessageBox.Show("Enter a numeric value.")
End If
' Clear the textbox for the next entry
txtTemp.Text = String.Empty
End If
End If
lblAver.Text = intAver.ToString()
End Sub
Private Sub chkCels_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkCels.CheckedChanged
'pull the answer from here
lblAver.Text = CStr(intTemp)
'the conversion formula
Celsius = CSng(Int((intTemp - 32) / 9) * 5)
txtCels.Text = CStr(Celsius)
End Sub
Private Sub lblCels_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
- AnnexTrunks
- Reputation: 0
- Posts: 1
- Joined: Thu Oct 20, 2011 12:52 am
- Highscores: 0
- Arcade winning challenges: 0
|
|