Results 1 to 4 of 4

Thread: [RESOLVED] interface question

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    403

    Resolved [RESOLVED] interface question

    hi all,

    i created an Interface named IChildCommands.

    implemented this in my form.

    when executing procedures of this interface, i use

    Code:
    DirectCast(Me.ActiveMdiChild, IChildCommands).Something
    i'm trying to look for a way to pass DirectCast(Me.ActiveMdiChild, IChildCommands) to an object so that i wouldn't be typing it all each time i want to use it.

    i want to do something like

    Code:
    Dim mychild As New Object = DirectCast(Me.ActiveMdiChild, IChildCommands)
    but the above code is wrong and i only used object as an example. in reality, i have no clue what variable type to use for this.

    please help.

    thanks.
    Last edited by adshocker; Mar 30th, 2009 at 09:36 PM.

    VB Version: Microsoft Visual Studio 2008 Professional Edition
    .NET Version: Microsoft .NET Framework Version 3.5
    OS: Windows XP SP3

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: interface question

    Of course you use type IChildCommands:
    vb.net Code:
    1. Dim mychild As IChildCommands = DirectCast(Me.ActiveMdiChild, IChildCommands)
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    403

    Re: interface question

    Quote Originally Posted by jmcilhinney View Post
    Of course you use type IChildCommands:
    vb.net Code:
    1. Dim mychild As IChildCommands = DirectCast(Me.ActiveMdiChild, IChildCommands)
    hi,

    thanks for the reply...

    i'm having a problem doing the suggested above...

    i now have the same thing you have

    Code:
    Dim mychild As IChildCommands = DirectCast(Me.ActiveMdiChild, IChildCommands)
    but the in the command

    Code:
    DirectCast(Me.ActiveMdiChild, IChildCommands)
    the bolded IChildCommands is underlined blue and says the "Type IChildCommands is not defined. The intellisense is picking it up though. not sure why it says its not defined.

    thanks.

    VB Version: Microsoft Visual Studio 2008 Professional Edition
    .NET Version: Microsoft .NET Framework Version 3.5
    OS: Windows XP SP3

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    403

    Re: interface question

    never mind... i figured it out...

    it seems that i can't declare it outside of a sub like that.

    i had to declare

    Code:
    Private mychild As IChildCommands
    outside the sub and in the form_load i had to assign it

    Code:
    mychild = DirectCast(Me.MdiParent, IChildCommands)
    don't know why though.

    thanks again..

    VB Version: Microsoft Visual Studio 2008 Professional Edition
    .NET Version: Microsoft .NET Framework Version 3.5
    OS: Windows XP SP3

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