dcsimg
Results 1 to 10 of 10

Thread: Object reference of DatGrid control

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2017
    Posts
    8

    Object reference of DatGrid control

    Hi

    I need to send different DataGrid control object references to a function. Something like this is possible with many controls like a Form:

    Code:
    Dim lForm as Form
    Set lForm = frmPrint
    
    msgbox(lForm.Caption)
    But it is not possible to do this with DataGrid control because it is diffrenet.
    Do you how I can do that?

    Code:
    Dim lGrid as ?  '( I tried DataGrid and Object here but not possible)
    set lGrid = myDataGrid
    
    Call myFunc(lGrid) 
    .
    .
    .
    
    Private myFunc(ByRef pMyGrid as ?)
    
       MsgBox pMyGrid.Caption
    
    End Function
    It is possible with MSFlexGrid control as well, but I need to use DataGrid control.

    Thanks
    Last edited by Al2017; Mar 13th, 2019 at 09:40 AM.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    33,916

    Re: Object reference of DatGrid control

    Moved from CodeBank, which is for finished snippets rather than questions.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2017
    Posts
    8

    Re: Object reference of DatGrid control

    Hi,

    What that means exactly "Moved from ..."

    Sorry, I am new

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,312

    Re: Object reference of DatGrid control

    I'm not sure what the problem might be, this works fine:

    Code:
    Option Explicit
    
    Private Sub DoSomething(ByVal DataGrid As DataGrid)
        MsgBox DataGrid.Caption
    End Sub
    
    Private Sub Form_Load()
        DoSomething DataGrid1
    End Sub
    Aside from a few reserved words (mostly the intrinsic scalar data types like Long, Integer, etc.) you can generally have a variable named the same as a type name. You normally want to pass an object reference by value unless the procedure is meant to change which instance of the object the passed variable points to.

  5. #5
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,312

    Re: Object reference of DatGrid control

    Could it be that you fell into the trap of using the crusty old VB5 DAO DBGrid we still had in VB6 for easily porting older projects? If so you'd get into trouble trying to use DataGrid variables.

  6. #6

    Thread Starter
    New Member
    Join Date
    Feb 2017
    Posts
    8

    Re: Object reference of DatGrid control

    I get

    Code:
    Type mismatch
    in

    Code:
    DoSomething DataGrid1
    Best

  7. #7

    Thread Starter
    New Member
    Join Date
    Feb 2017
    Posts
    8

    Re: Object reference of DatGrid control

    your solution is working like this:

    Code:
    Private Sub DoSomething(ByVal DataGrid As Object)
        MsgBox DataGrid.Caption
    End Sub

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    33,916

    Re: Object reference of DatGrid control

    Quote Originally Posted by Al2017 View Post
    Hi,

    What that means exactly "Moved from ..."

    Sorry, I am new
    That means that you posted a question in the CodeBank, and the question was moved here, where it belongs.
    My usual boring signature: Nothing

  9. #9

    Thread Starter
    New Member
    Join Date
    Feb 2017
    Posts
    8

    Re: Object reference of DatGrid control

    It works if I use MSDataGridLib.DataGrid for the type definition as well.
    Thank you for your attention @dilettante

  10. #10
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,312

    Re: Object reference of DatGrid control

    That suggests you have somehow defined the "DataGrid" type twice or more. But yes, it is usually a good idea to qualify the type by the type library name where it is defined.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width