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
Re: Object reference of DatGrid control
Moved from CodeBank, which is for finished snippets rather than questions.
Re: Object reference of DatGrid control
Hi,
What that means exactly "Moved from ..."
Sorry, I am new ;)
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.
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.
Re: Object reference of DatGrid control
I get
in
Code:
DoSomething DataGrid1
Best
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
Re: Object reference of DatGrid control
Quote:
Originally Posted by
Al2017
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.
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
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.