School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
Welcome to Dream.In.Code
Become an Expert!

Join 340,150 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 3,868 people online right now. Registration is fast and FREE... Join Now!



VB Temperature Converter

Page 1 of 1

VB Temperature Converter Rate Topic: -----

#1 jaj45  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 23
  • Joined: 22-March 09


Dream Kudos: 0

Posted 03 June 2009 - 10:31 PM

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?


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



Was This Post Helpful? 0
  • +
  • -


#2 June7  Icon User is offline

  • D.I.C Addict
  • Icon
  • Group: Members w/DIC++
  • Posts: 591
  • Joined: 09-December 08


Dream Kudos: 0

Posted 03 June 2009 - 11:39 PM

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:
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: 03 June 2009 - 11:42 PM

Was This Post Helpful? 0
  • +
  • -

#3 jaj45  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 23
  • Joined: 22-March 09


Dream Kudos: 0

Posted 04 June 2009 - 12:02 AM

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?
Was This Post Helpful? 0
  • +
  • -

#4 June7  Icon User is offline

  • D.I.C Addict
  • Icon
  • Group: Members w/DIC++
  • Posts: 591
  • Joined: 09-December 08


Dream Kudos: 0

Posted 04 June 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.
Was This Post Helpful? 0
  • +
  • -

#5 jaj45  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 23
  • Joined: 22-March 09


Dream Kudos: 0

Posted 04 June 2009 - 12:16 AM

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?


View PostJune7, on 4 Jun, 2009 - 12:10 AM, said:

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.

Was This Post Helpful? 0
  • +
  • -

#6 June7  Icon User is offline

  • D.I.C Addict
  • Icon
  • Group: Members w/DIC++
  • Posts: 591
  • Joined: 09-December 08


Dream Kudos: 0

Posted 04 June 2009 - 12:40 AM

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...g...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: 04 June 2009 - 01:04 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1


Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

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

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month