Results 1 to 4 of 4

Thread: why in VB.Net I’m getting this error

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Posts
    376

    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

  2. #2
    Fanatic Member khalik_ash's Avatar
    Join Date
    Aug 2002
    Location
    Singapore
    Posts
    724
    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...

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

  4. #4
    Lively Member
    Join Date
    Feb 2003
    Location
    UK
    Posts
    95
    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
  •  



Click Here to Expand Forum to Full Width