8 Replies - 1765 Views - Last Post: 20 February 2009 - 06:40 PM Rate Topic: -----

#1 nritzau  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 66
  • Joined: 31-January 09

Temperature Converter

Posted 20 February 2009 - 05:40 PM

I have been trying to make this Temperature Converter and it comes up a error when i select a radio button, Help would be appreciated.

Public Class Form1
	Dim celsiusanswer As Single
	Dim farenheitanswer As Single
	Dim arithmeticprocess As String
	Dim arithmeticprocess2 As String

	Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
		TextBox1.Text = ""
		TextBox2.Text = ""
	End Sub

	Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
		TextBox2.Text = (TextBox1.Text - 32) / 1.8
	End Sub

	Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
		TextBox2.Text = (TextBox1.Text * 1.8) + 32
	End Sub
End Class

This post has been edited by nritzau: 20 February 2009 - 05:53 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Temperature Converter

#2 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 773
  • View blog
  • Posts: 5,097
  • Joined: 08-December 08

Re: Temperature Converter

Posted 20 February 2009 - 05:46 PM

What errors are you getting? As I see you are using implicit conversion from double values to string. I would recommend performing the calculations with explicitly converted values. Relying on implicit conversion may cause problems while running the application.

For some tips, take a look at this MSDN article:
http://msdn.microsof...k58(VS.71).aspx
Was This Post Helpful? 0
  • +
  • -

#3 nritzau  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 66
  • Joined: 31-January 09

Re: Temperature Converter

Posted 20 February 2009 - 05:59 PM

View PostCore, on 20 Feb, 2009 - 04:46 PM, said:

What errors are you getting? As I see you are using implicit conversion from double values to string. I would recommend performing the calculations with explicitly converted values. Relyinng on implicit conversion may cause problems while running the application.

For some tips, take a look at this MSDN article:
http://msdn.microsof...k58(VS.71).aspx


If i change the code and put a button it works fine but when i have a radio button it dosent work , can you help me with a code

This post has been edited by nritzau: 20 February 2009 - 06:07 PM

Was This Post Helpful? 0
  • +
  • -

#4 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 773
  • View blog
  • Posts: 5,097
  • Joined: 08-December 08

Re: Temperature Converter

Posted 20 February 2009 - 06:16 PM

I just tried your code in a testing environment and it works fine. What specifically is not working? You can't see the result or there are errors?
Was This Post Helpful? 0
  • +
  • -

#5 nritzau  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 66
  • Joined: 31-January 09

Re: Temperature Converter

Posted 20 February 2009 - 06:25 PM

View PostCore, on 20 Feb, 2009 - 05:16 PM, said:

I just tried your code in a testing environment and it works fine. What specifically is not working? You can't see the result or there are errors?


When i debug the code and test it, I click on one of the radio buttons E.g. Celcius to Farenhiet. But than the Debug version freezes and on the code it has a higlight yellow error on the radio button i clicked

View PostCore, on 20 Feb, 2009 - 05:16 PM, said:

I just tried your code in a testing environment and it works fine. What specifically is not working? You can't see the result or there are errors?


The Error Says Conversion from string "" to type 'Double' is not valid
Was This Post Helpful? 0
  • +
  • -

#6 EB547  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 14
  • Joined: 20-February 09

Re: Temperature Converter

Posted 20 February 2009 - 06:30 PM

I Tried it and got a error as well. I Don't really get it. The code overall looks like it would run, but it doesn't.
Was This Post Helpful? 1
  • +
  • -

#7 nritzau  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 66
  • Joined: 31-January 09

Re: Temperature Converter

Posted 20 February 2009 - 06:32 PM

View PostEB547, on 20 Feb, 2009 - 05:30 PM, said:

I Tried it and got a error as well. I Don't really get it. The code overall looks like it would run, but it doesn't.


yes but it does'nt run anyone got any ideas for the code, help will be appreciated
Was This Post Helpful? 0
  • +
  • -

#8 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 773
  • View blog
  • Posts: 5,097
  • Joined: 08-December 08

Re: Temperature Converter

Posted 20 February 2009 - 06:35 PM

Quote

The Error Says Conversion from string "" to type 'Double' is not valid


There is the error - if you click the radio button but the text box is empty, the error si triggered. You have to add some verification to your code:

If TextBox1.Text = ""
MessageBox.Show ("Please, enter a value to convert!")
Else
TextBox2.Text = (TextBox1.Text * 1.8) + 32
End If


Was This Post Helpful? 1
  • +
  • -

#9 nritzau  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 66
  • Joined: 31-January 09

Re: Temperature Converter

Posted 20 February 2009 - 06:40 PM

View PostCore, on 20 Feb, 2009 - 05:35 PM, said:

Quote

The Error Says Conversion from string "" to type 'Double' is not valid


There is the error - if you click the radio button but the text box is empty, the error si triggered. You have to add some verification to your code:

If TextBox1.Text = ""
MessageBox.Show ("Please, enter a value to convert!")
Else
TextBox2.Text = (TextBox1.Text * 1.8) + 32
End If



Hey, it works thanks for all your help and everyone else who posted on this forum, Problem Solved! :^: :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1