Wrox Programmer Forums
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 27th, 2008, 05:04 AM
Registered User
 
Join Date: May 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Re: Code Error

I need some advice on the following code in the "Beginning VB.Net 2003" book:

On pg 159, in the 2nd grey block of code, the 6th line: Return lstCustomers.Items(lstCustomers.SelectedIndex)

When I type this in my code editor, it gives me the following error:

"Option Strict On disallows implicit conversions from System.Object to StructureDemo.Customer"

I have done exactly what the author has done & checked it again & again but it still gives me this error.

The same thing happens with the code given on pg 164, in the 1st grey block of code, line 4: Return Me.List.Item(Index)

Please can someone help me with this, I am new to programming and cannot figure it out myself.
 
Old May 27th, 2008, 07:04 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Hi there.. You have option strict on. This means that you have to make any type conversion explicit to the system. You can't transform an object to another type (even if they are compatible) unless you specify what type is your destination (this is to avoid any type of conversion error). This is a common practice in languages like C# or even C++, but Vb always allow implicit conversions. You have 2 ways to solve this. First one, Turn off option strict (in the properties of the project). Second, make the conversions explicits: for example:
Code:
Return ctype(lstCustomers.Items(lstCustomers.SelectedIndex),StructureDemo.Customer)
I always prefer to keep option strict on and make the conversions myself, but you can do whatever you want..

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
Error in Code NadAf BOOK: Ivor Horton's Beginning Visual C++ 2005 0 February 18th, 2008 11:16 PM
Code error reverand Excel VBA 1 November 15th, 2006 02:08 AM
Code error??? emyr BOOK: Beginning Java 2 1 October 31st, 2006 05:47 PM
Code error!?!? Brian Campbell BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 3 November 26th, 2004 07:47 PM
Error displayed with error trap code stoneman Access 4 February 28th, 2004 02:53 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.