VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 306,832 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,761 people online right now. Registration is fast and FREE... Join Now!




VB Temperature Converter

 

VB Temperature Converter

jaj45

3 Jun, 2009 - 10:31 PM
Post #1

New D.I.C Head
*

Joined: 22 Mar, 2009
Posts: 17



Thanked: 1 times
My Contributions






I need to make my program do the following:

Write a program that calculates average daily temperatures and summary statistics. The user will be prompted to enter a Fahrenheit temperature as a value with one decimal place and to select the name of the technician entering the temperature. The user will have the option to see the Celsius equivalent of the entered Fahrenheit temperature. The program will display the average temperature of all entered temperatures. The results are displayed when the user hits ENTER, uses the access key or clicks the Calculate button. The user will be given the opportunity to enter another temperature when the user hits ESC, uses the access key or clicks the Clear button. The user will exit the program by clicking the Exit button or using its access key. The Exit button will also display the summary statistics: 1) the number of temperatures entered by each technician and 2) the average temperature of all entered temperatures. Calculations should only be done if a numeric value between 32.0 and 80.0 (inclusive) degrees for temperature is entered and a technician has been selected.

Below is what I have so far. I still need to format it so it is organized better. It does what I want it to do but not exactly. I keep getting an error when I hit the clear button as well. Can anyone help me fix the error and help me with the end stastistics so it actually displays the numbers instead of just the property name?

And also it is not doing what I would like it to do as far as storing each number that I enter to determine the average. Can anyone help?

CODE


Option Strict On

Imports System.Convert
Imports Microsoft.VisualBasic.ControlChars


Public Class Form1


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


Dim intEntriesJen As Integer = 0
Dim intEntriesCliff As Integer = 0
If radJen.Checked = True Then
intEntriesJen += 1
End If
If radCliff.Checked = True Then
intEntriesCliff += 1
End If

Dim dblAvg As Double
dblAvg = CDbl(txtTemp.Text) / intEntriesJen + intEntriesCliff
lblAverage.Text = CStr(dblAvg)


End Sub


Private Sub chkCelsius_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkCelsius.CheckedChanged

Dim dblCelsius As Double
dblCelsius = (CDbl(txtTemp.Text) - 32) * 5 / 9
lblCelsius.Text = CStr(dblCelsius)


End Sub

Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
' Clear the numbers
txtTemp.Clear()
lblAverage.Text = String.Empty
lblCelsius.Text = String.Empty
radCliff.Checked = False
radJen.Checked = False
chkCelsius.Checked = False

' Reset the focus
txtTemp.Focus()
End Sub

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
'Ends Application and shows summary statistics

MessageBox.Show("Jen entered intEntriesJen entries." & ControlChars.CrLf & "Cliff entered intEntriesCliff entries." & _
ControlChars.CrLf & "The average temperature is _.", "Status")

Me.Close()
End Sub
End Class




User is offlineProfile CardPM
+Quote Post


June7

RE: VB Temperature Converter

3 Jun, 2009 - 11:39 PM
Post #2

D.I.C Regular
Group Icon

Joined: 9 Dec, 2008
Posts: 485



Thanked: 38 times
My Contributions
What is the error when you press Clear? Which code line fails?

For the average calc, don't need to store each number entered, need a running total and a running count. Use AfterUpdate event of the textbox with code that will add the new values to running sum and count. Use public declared variables to store the running calcs. Display in msgbox by:
CODE
MessageBox.Show("Jen entered " & intEntriesJen & " entries." & ControlChars.CrLf & "Cliff entered " & intEntriesCliff & " entries." & _
ControlChars.CrLf & "The average temperature is " & dblSumTemp / dblCount & ".", "Status")


This post has been edited by June7: 3 Jun, 2009 - 11:42 PM
User is offlineProfile CardPM
+Quote Post

jaj45

RE: VB Temperature Converter

4 Jun, 2009 - 12:02 AM
Post #3

New D.I.C Head
*

Joined: 22 Mar, 2009
Posts: 17



Thanked: 1 times
My Contributions
Thanks for the message box help. I fixed the error that appears when I hit the clear button so nevermind on that.

I'm not sure what you mean by AfterUpdate event though. Can you possibly explain?
User is offlineProfile CardPM
+Quote Post

June7

RE: VB Temperature Converter

4 Jun, 2009 - 12:10 AM
Post #4

D.I.C Regular
Group Icon

Joined: 9 Dec, 2008
Posts: 485



Thanked: 38 times
My Contributions
Like the Click event for a button, textboxes, comboboxes, listboxes can have an event called AfterUpdate. User enters or selects a value and when they Tab or Enter the AfterUpdate event will be triggered because they have 'updated' the box and code in the event will process. You should be able to see the events available to an object in its Properties box.
User is offlineProfile CardPM
+Quote Post

jaj45

RE: VB Temperature Converter

4 Jun, 2009 - 12:16 AM
Post #5

New D.I.C Head
*

Joined: 22 Mar, 2009
Posts: 17



Thanked: 1 times
My Contributions
Ok. I understand now. I'm using VB 2008, just to double check is it called the same thing in here as it is in 2005?


QUOTE(June7 @ 4 Jun, 2009 - 12:10 AM) *

Like the Click event for a button, textboxes, comboboxes, listboxes can have an event called AfterUpdate. User enters or selects a value and when they Tab or Enter the AfterUpdate event will be triggered because they have 'updated' the box and code in the event will process. You should be able to see the events available to an object in its Properties box.


User is offlineProfile CardPM
+Quote Post

June7

RE: VB Temperature Converter

4 Jun, 2009 - 12:40 AM
Post #6

D.I.C Regular
Group Icon

Joined: 9 Dec, 2008
Posts: 485



Thanked: 38 times
My Contributions
Sorry, AfterUpdate event appears to be an Access feature, not VB6 nor VB.Net. Closest emulation I could find was in this posting.
http://www.microsoft.com/communities/newsg...p;sloc=&p=1.
If can't get running variables to work, alternatives I see are to use array or gridview, although would still need array as public and an event that would be triggered when value entered to save to array or gridview.

This post has been edited by June7: 4 Jun, 2009 - 01:04 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/20/09 10:52PM

Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month