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

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



Need some help with a US to metric converter

Page 1 of 1

Need some help with a US to metric converter Rate Topic: -----

#1 Amerowolf  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 3
  • Joined: 31-January 09


Dream Kudos: 0

Post icon  Posted 31 January 2009 - 12:14 PM

I need some help coding something. I'm quite new so...yeah.

	Private Sub DistanceConvertButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DistanceConvertButton.Click
		'converts Distances to metric
		Dim numInch As Decimal
		Dim numFeet As Decimal
		Dim numMile As Decimal
		Dim numCenti As Decimal
		Dim numMeter As Decimal
		Dim numKilo As Decimal

		If txtInch.Text <> " " Then
			numInch = txtInch.Text * 2.54
			txtCenti.Text = numInch
		Else
			numCenti = txtCenti.Text / 2.54
			txtInch.Text = numCenti
		End If

		If txtFeet.Text <> " " Then
			numFeet = txtFeet.Text * 0.3048
			txtMeter.Text = numFeet
		Else
			numMeter = txtMeter.Text / 0.3048
			txtFeet.Text = numMeter
		End If
		If txtMile.Text <> " " Then
			numMile = txtMile.Text * 1.61
			txtKilo.Text = numMile
		Else
			numKilo = txtKilo.Text / 1.61
			txtMile.Text = numKilo
		End If
	End Sub



I'm trying to get this to work so that if I type some measurement in metric it will convert to US measurements, and if I type something in US measurements it will convert to Metric.

Before I up in all the If then statements it converted to US to metric just fine, though I don't know if the actual conversions were correct, but it worked anyway. Now it just give me an error saying IvalidCastException unhandled.

And I'm not sure what that means...
Was This Post Helpful? 0
  • +
  • -


#2 PsychoCoder  Icon User is offline

  • apt-get install DIC.bin
  • Icon
  • View blog
  • Group: Admins
  • Posts: 16,211
  • Joined: 26-July 07


Dream Kudos: 12400

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

Posted 31 January 2009 - 12:39 PM

Moved to VB.NET :)
Was This Post Helpful? 0
  • +
  • -

#3 Amerowolf  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 3
  • Joined: 31-January 09


Dream Kudos: 0

Posted 31 January 2009 - 12:40 PM

Oh. Sorry about that, thanks for the move, man.
Was This Post Helpful? 0
  • +
  • -

#4 nightscream  Icon User is offline

  • D.I.C Head
  • PipPip
  • Group: Members
  • Posts: 119
  • Joined: 04-December 08


Dream Kudos: 0

Posted 31 January 2009 - 03:06 PM

that means that there is a problem with conversion.
You should debug it next time, an empty textbox is not " " but just "" change it and it should work.
Or you can also use Nothing or String.empty I think there are some more.

This post has been edited by nightscream: 31 January 2009 - 03:14 PM

Was This Post Helpful? 0
  • +
  • -

#5 Amerowolf  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 3
  • Joined: 31-January 09


Dream Kudos: 0

Posted 01 February 2009 - 10:18 AM

I replaces the " " with Nothing and it worked the first time, but on the second run it gave me the same invalid IvalidCastException unhandled error on

numInch = txtInch.Text * 2.54


Okay, but once I stop debugging, the program works fine. Thanks, man. Now hopefully things go smoother with the temperature and liquid conversions.
Was This Post Helpful? 0
  • +
  • -

#6 Jayman  Icon User is offline

  • Student of Life
  • Icon
  • View blog
  • Group: Admins
  • Posts: 8,832
  • Joined: 26-December 05


Dream Kudos: 500

Expert In: Everything

Posted 01 February 2009 - 12:28 PM

Set the textbox to be an empty string, do not clear it using Nothing.

TextBox.Text.Clear()

TextBox.Text = ""

TextBox.Text = String.Empty


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