Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21236

Pass control reference from form to module

$
0
0
I'm not sure the title of this isn't a little misleading .. here's what I want to do:

I have at least one MSFlexGrid on each form using VB6. I have to manually set the height and width of the grid control. I'm basically using the following code to do this: (There is actually a bit more to the code but this should suffice ...

Code:

Me.grid.Width = 0
For X = 0 To Me.grid.Cols - 1
    Me.grid.Width = Me.grid.Width + Me.grid.ColWidth(X) + Screen.TwipsPerPixelX
Next

Me.grid.Height = 0
For X = 0 To Y
    Me.grid.Height = Me.grid.Height + Me.grid.RowHeight(X) + 1 + Screen.TwipsPerPixelY
Next

The problem is that I need to do this for every grid almost every time it is populated. Sometimes the grid might have 1 line .. other times 2 or more. Obviously if I do not resize the grid and it should only have 1 line but the last query filled it with 2, the leftover line will remain visible. I could reinitialize the grid every time a new recordset is inserted into it but that also seems wasteful to me. I could make a subroutine in each form to do it but that too would be wasteful as I'd have to put the same code in each form (not to mention passing the control name which is my problem). So the logical thing is to put the code in a module. I tried this code in a module ...

Code:

Public Sub ResizeGrid(GrdName As Object)

GrdName.Width = 0
For X = 0 To Me.GrdName.Cols - 1
    Me.GrdName.Width = Me.GrdName.Width + Me.GrdName.ColWidth(X) + Screen.TwipsPerPixelX
Next

Me.GrdName.Height = 0
For X = 0 To Y
    Me.GrdName.Height = Me.GrdName.Height + Me.GrdName.RowHeight(X) + 1 + Screen.TwipsPerPixelY
Next

End Sub

But I get errors when I try to call the routine ... such as ResizeGrid(grdOccupied)
I tried changing the reference in the routine to a control with no luck.

So ... how do I pass the name of the grid I want to resize to a subroutine in a module?

Thanks
Ken

Viewing all articles
Browse latest Browse all 21236

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>