-
Mar 13th, 2019, 09:20 AM
#1
Thread Starter
New Member
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.
-
Mar 13th, 2019, 10:07 AM
#2
Re: Object reference of DatGrid control
Moved from CodeBank, which is for finished snippets rather than questions.
My usual boring signature: Nothing
-
Mar 13th, 2019, 10:15 AM
#3
Thread Starter
New Member
Re: Object reference of DatGrid control
Hi,
What that means exactly "Moved from ..."
Sorry, I am new
-
Mar 13th, 2019, 11:51 AM
#4
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.
-
Mar 13th, 2019, 11:55 AM
#5
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.
-
Mar 13th, 2019, 12:04 PM
#6
Thread Starter
New Member
Re: Object reference of DatGrid control
I get
in
Code:
DoSomething DataGrid1
Best
-
Mar 13th, 2019, 12:13 PM
#7
Thread Starter
New Member
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
-
Mar 13th, 2019, 12:18 PM
#8
Re: Object reference of DatGrid control
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.
My usual boring signature: Nothing
-
Mar 13th, 2019, 12:18 PM
#9
Thread Starter
New Member
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
-
Mar 13th, 2019, 12:35 PM
#10
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|