2 Replies - 903 Views - Last Post: 14 September 2009 - 06:46 AM Rate Topic: -----

#1 allbuzinezz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 21-July 09

Conversion from string "Expenses for Meals and Entertain" to

Post icon  Posted 13 September 2009 - 09:31 PM

WHEN I RUN IT KEEP SAYING Conversion from string "Expenses for Meals and Entertain" to type 'Double' is not valid. A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll AND POINTS TO
meals As Double = CType(TxtMeals.Text, Double) IT THOUGHT I HAD THE CONVERSION TYPE CORRECT PLEASE EXPLAIN WHAT I DID WRONG

Public Class Form1
	Const MealPercentage As Double = 50 '//50%
	
	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
	   [code]
		Dim fmtStr As String = "{0, -26}  {1, -10:C2}"
		Dim meals As Double = CType(TxtMeals.Text, Double)
		Dim airline As Double = CType(TxtAirLine.Text, Double)
		Dim lodging As Double = CType(TxtLodging.Text, Double)
		Dim taxi As Double = CType(TxtTaxi.Text, Double)

		Dim sum As Double = 0 '//Total
		Dim meals2 As Double = 0
		Dim SumIncludingPercentageAddition As Double = 0

		With LstResults.Items
			sum = CType(TxtAirLine.Text, Double) + CType(TxtLodging.Text, Double) + CType(TxtTaxi.Text, Double)
			meals2 = (meals * (MealPercentage / 100))
			SumIncludingPercentageAddition = sum + meals2


			.Clear()
			.Add("Business Travel Expense")
			.Add("")
			.Add("Trip to attend meeting of")
			.Add(Txbx1.Text)
			.Add(TextBox3.Text & " in " & TextBox2.Text)
			.Add("")
			.Add(String.Format(fmtStr, "Meals and entertainment", meals))
			.Add(String.Format(fmtStr, "Airplane fare", airline))
			.Add(String.Format(fmtStr, "Lodging", lodging))
			.Add(String.Format(fmtStr, "Taxi fares", taxi))
			.Add("")
			.Add(String.Format(fmtStr, "Total other than meals and entertainment:", sum))
			.Add(String.Format(fmtStr, "50% of meals and entertainment:", meals2))

			.Add(String.Format(fmtStr, "Total Including Meals:", sum + meals))
			.Add(String.Format(fmtStr, "Total Including Meals + 50%:", sum + meals + meals2))



		End With

		LstResults.Visible = True

	End Sub

End Class

This post has been edited by allbuzinezz: 13 September 2009 - 09:35 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Conversion from string "Expenses for Meals and Entertain" to

#2 no2pencil  Icon User is offline

  • Head MFIC
  • member icon

Reputation: 5066
  • View blog
  • Posts: 26,448
  • Joined: 10-May 07

Re: Conversion from string "Expenses for Meals and Entertain" to

Posted 13 September 2009 - 10:56 PM

** Moved to VB.NET forum, & renamed title to be more descriptive of topic **
Was This Post Helpful? 0
  • +
  • -

#3 mark.bottomley  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 176
  • View blog
  • Posts: 990
  • Joined: 22-April 09

Re: Conversion from string "Expenses for Meals and Entertain" to

Posted 14 September 2009 - 06:46 AM

It sounds like TxtMeals.Text contains "Expenses for Meals and Entertain", not a numeric value as expected.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1