|
-
Jun 30th, 2003, 07:47 AM
#1
Thread Starter
Hyperactive Member
why in VB.Net I’m getting this error
Could anyone let me know why in VB.Net I’m getting this error on the third line of code below?
ERROR:
Option Strict On disallows implicit conversions from 'System.Object' to 'VBNET.HowTo.Address'.
CODE:
ReadOnly Property CurrentAddress() As Address
Get
Return AddressBook.Items(CurrentAddressIndex - 1)
End Get
End Property
I declare like this:
Public AddressBook As AddressBook
Private _currentAddressIndex As Integer
Thanks
-
Jun 30th, 2003, 08:14 AM
#2
Fanatic Member
its always better to use error handler...
as i am not on my pc and i cannot check i suggest to use error handle and see the error message...
-
Jun 30th, 2003, 10:11 AM
#3
Sounds like AddressBox is a standard collection and not type safe, which means that the Items property returns the generic object type and you need it to return an Address type. You can just cast the returned object to the Address type to fix it.
Return CType(AddressBook.Items(CurrentAddressIndex - 1), GetType(Address))
or
Return CType(AddressBook.Items(CurrentAddressIndex - 1), Address)
One of those will work I forget if you need gettype there or not.
-
Jul 1st, 2003, 08:07 AM
#4
Lively Member
No, the GetType is not needed for CType in this case.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|