473,396 Members | 1,918 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,396 software developers and data experts.

Invalid cast in code but not in command window

Hi,

I am doing some code which involves type conversion and have run into a
problem I find odd.

I have a control of type class1 in a referenced assembly called
subclassedcontrols.
The line below used to work in other code, Facet is a property of my class1
control which inherits from a normal textbox
MessageBox.Show(CType(ctl, SubClassedControls.Class1).Facet & ctl.Text)

Exception message is:

An unhandled exception of type 'System.InvalidCastException' occurred in
VisualNotepad.exe

Additional information: Specified cast is not valid.

BUT this line executes OK in the command window

?CType(ctl, SubClassedControls.Class1).Facet & ctl.Text

Any pointers? I cannot understand why it should work in the command window
but not in the code running

Best regards,

Andrew
Nov 21 '05 #1
1 1167
On Wed, 24 Nov 2004 13:59:52 +0000 (UTC), Andrew wrote:
The line below used to work in other code, Facet is a property of my class1
control which inherits from a normal textbox
Is Facet a string? Perhaps the MessageBox is expecting a string and cannot
cast Facet to a string. If it is descended from a textbox, perhaps you
could use Facet.Text
MessageBox.Show(CType(ctl, SubClassedControls.Class1).Facet & ctl.Text)

BUT this line executes OK in the command window

?CType(ctl, SubClassedControls.Class1).Facet & ctl.Text

The two lines are not strictly the same. One uses MessageBox. Perhaps
there is something about using messageBox that is causing the problems.
Any pointers? I cannot understand why it should work in the command window
but not in the code running


Good luck.

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

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...
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...
2
by: adams114 | last post by:
I am having a strange problem with invalid type casts. I am trying to update a MS SQL Database with a stored procedure. When I setup the parameters collection for the command object I get a invalid...
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...
21
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...
2
by: none | last post by:
Hi, I'm opening a popup window with JavaScript. It has a command button. This is from the primary source (opener) window: ###################################################################...
0
by: balukrishnan | last post by:
Hi... I am trying to create an object of Shdocvw.InternetExplorer class, using which I need to launch a particular URL(A JSP Webpage). Then I need to get the document of the page loaded. But...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.