Results 1 to 4 of 4

Thread: exposing an inner control

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2002
    Posts
    235

    exposing an inner control

    I made three controls, a Peg, a Pegboard, and a Solution. There is a control array of Pegs on the Pegboard, and one Pegboard on the Solution. Now, my form has a Solution on it, and it needs to be able to access properties of the pegs. I did this by putting the following function in the pegboard control:

    Code:
    ‘This is in PegBoard
    Public Function GetPeg(i As Integer) As Peg
        If i > m_numOfPegs Then
            MsgBox "Error: invalid peg: " & i
            Exit Function
        End If
        
        Set GetPeg = Peg(i)
    End Function
    I can get this to work in my code for Solution easily:

    Code:
           ‘This line in Solution works fine
            PegBoard.GetPeg(i).ShowColor (False)
    I want the form to be oblivious of the fact that there’s an extra level of abstraction (the Pegboard). So I created a GetPeg function for the Solution control:
    Code:
    ‘This is in Solution
    Public Function GetPeg(Index As Integer) As Peg
        Set GetPeg = PegBoard.GetPeg(Index)
    End Function
    And want to directly access a peg from the solution like this:
    Code:
    ‘This is in Form
       Dim p As Peg
    
        Set p = Solution.GetPeg(i)
    But this causes an runtime error ‘13’ type mis-match. It seems that my mult-leveling is causing problems. Does anyone know if what I’m trying to do is possible? I guess I could expose my pegboard and use Solution.GetPegboard.GetPeg(i), but that’s clunky, and I would prefer not to do it that way.

    Thanks.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Apr 2002
    Posts
    235
    I am using VB 5, and have seen allusions to the fact that VB 6 was the first version that supports returning a user defined type. Are custom controls considered user defined types? It seem like this isn't the answer, though, because I did return a peg once.

  3. #3
    jim mcnamara
    Guest
    No they are considered objects and as such you can pass them back and forth as a variant.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Apr 2002
    Posts
    235

    ahhhh

    Thanks, Jim, your reply definately put me on the right track. I found out that the problem doesn't seem to be with returning a Peg at all. Rather, the parameter Index needs to be a variant. I can't fathom why this would be. If anyone can explain the reasoning behind it, I'd love to hear it.

    Thanks.

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