473,414 Members | 1,777 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Invalid Cast Excepton

I get this Error Message and I am lost as to how to fix it. Can someone please help? My code is--
Expand|Select|Wrap|Line Numbers
  1.  Dim a, b, r, h As Double
  2.     Dim v As Double
  3.     Const Pi As Double = 3.14
  4.  
  5.  'Assign text box values to variables
  6.         a = CDbl(CStr(CDbl(TextBox1.Text)))
  7.         b = CDbl(CStr(CDbl(TextBox2.Text)))
  8.         r = CDbl(CStr(CDbl(TextBox3.Text)))
  9.         h = CDbl(CStr(CDbl(TextBox4.Text)))
  10.         'Determine checked button and calculate
  11.         Try
  12.             If RadioButton1.Checked = True Then
  13.  
  14.             End If
  15.             v = CDbl(CStr(Sqrt(CDbl(a) ^ 2) + (CDbl(b) ^ 2)))
  16.             TextBox5.Text = CStr(v)
  17.  
  18.         Catch When Err.Number = 6 'if Overflow
  19.             MsgBox("Overflow")
  20.         Catch When Err.Number = 11 'if Division by Zero
  21.             MsgBox("Zero Error")
  22.         Catch When Err.Number = 13 'if typing error
  23.             MsgBox("Typing Error")
  24.         End Try
  25.  
  26.  
  27.         'Uses formula to calculate volume of a cylinder
  28.         Try
  29.             If RadioButton2.Checked = True Then
  30.  
  31.             End If
  32.             v = CDbl(CStr((CDbl(r) * CDbl(r)) * 3.14 * CDbl(h)))
  33.             TextBox5.Text = CStr(v)
  34.         Catch When Err.Number = 6 'if Overflow
  35.             MsgBox("Overflow")
  36.         Catch When Err.Number = 11 'if Division by Zero
  37.             MsgBox("Zero Error")
  38.         Catch When Err.Number = 13 'if typing error
  39.             MsgBox("Typing Error")
  40.  
PLEASE HELP
Apr 27 '10 #1
2 1467
Frinavale
9,735 Expert Mod 8TB
You may be getting this error if the TextBoxes contains Nothing...I just glanced at your code though so I'm not sure.

Which line is the error occurring on?

-Frinny
Apr 27 '10 #2
debasisdas
8,127 Expert 4TB
the culprit is the very first line.

in your code only the variable h is double.remaining 3 are variant by default.
Apr 28 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: | last post by:
When I execute the following (with an OleDBDataAdapter), wanting to add a row to a visual foxpro table: myrow= datasetTarget.Tables(0).NewRow 'fill all columns here like.. row(i)= myvalue '...
3
by: Krung Saengpole | last post by:
Hi, I used SQL Server 2000 Personal Edition. I created a stored procedure having input parameters as smallint,tinyint,char,varchar and smalldatetime. When I executed it by Query Analyzer, it's...
3
by: Ole Hanson | last post by:
Hi Trying to cast an exception to the correct type, I encounter some "strange" experiences: The compiler complains that the variable "t" is unknown in line 2 (Exception trueException =...
0
by: Alan Z. Scharf | last post by:
Win Server 2003 VS.Net 2003 --------------- 1. I'm having the same problem below on all six of my pages with a datagrid item. 2. These pages all worked fine for months until problem started....
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
3
by: John Howard | last post by:
Making the following call to a local MSAccess database works fine: Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) Dim intRows As Integer Dim strSQL As String Dim ds As New...
1
by: Hifni Shahzard | last post by:
Hi, I got a stored procedure, where it returns a value. But if I execute it. It gives an error as "Invalid cast from System.Int32 to System.Byte.". To make clear how do I execute this, below I'm...
15
by: David | last post by:
Hi, I have built a web application that will be a very high profile application. We had tested it, demonstrated it and shown that it all works. On a dress rehearsal run through, it failed...
7
by: Chris Thunell | last post by:
I'm trying to loop through an exchange public folder contact list, get some information out of each item, and then put it into a vb.net datatable. I run though the code and all works fine until i...
7
by: chance | last post by:
Getting and error on this first line of code: //inspector phone theField = reader.GetString(20); builder.MoveToBookmark("inspector_phone"); builder.Write(theField); the first line is...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.