Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Joining variables to point to an object...?? 1

Status
Not open for further replies.

Roebuck

Technical User
Apr 23, 2003
14
0
0
GB
A beginners query... I want to set up a generic function (see below) to set each column width on a Flexgrid in VB6.

At the moment it should pass the form name, control name and up to 10 values (width), then set each column to the appropriate value.

Please can someone help with how to concatenate variables which will successfully point at a control on a form,
e.g. strForm.strControl.ColWidth(2) =2000

Thanks in advance.




Function fncSetUpHFlexGridCols(strForm, strControl, intCol1, intCol2, intCol3, intCol4, intCol5, intCol6, intCol7, intCol8, intCol9, intCol10)
'Called With: fncSetUpHFlexGridCols("Form1", "MSHFlexGrid1", 1000, 1000, 2000, 1000, 500, 0, 0, 0, 0, 0)

Dim intSizes, i As Integer
intSizes = Array(intCol1, intCol2, intCol3, intCol4, intCol5, intCol6, intCol7, intCol8, intCol9, intCol10)

For i = 0 To 9
'Form1.MSHFlexGrid1.ColWidth(2) = 2000
strForm.strControl.ColWidth(2) = intSizes(i)
Next i

End Function


 
If you pass a the MSHFlexGrid1 object as one of the parameters you don't need to include the form name, and if you pass a Variant containing an array as the other parameter:

Function fncSetUpHFlexGridCols(ctlControl As MSFlexGrid, varColumnArray As Variant)
Dim i As Integer

For i = LBound(varColumnArray) to UBound(varColumnArray)
ctlControl.ColWidth(2) = VarColumnArray(i)
Next i
End Function

The above is untested, but should work!


Andy
"Logic is invincible because in order to combat logic it is necessary to use logic." -- Pierre Boutroux
"Why does my program keep showing error messages every time something goes wrong?"
 

Thanks very much, I got it working in a couple of minutes!

Simple when you know how...
 
> Simple when you know how...

How very true! Glad I could help. Thanks for the star.


Andy
"Logic is invincible because in order to combat logic it is necessary to use logic." -- Pierre Boutroux
"Why does my program keep showing error messages every time something goes wrong?"
 
Hi, Just another way, not only for sizes, but for all column setings. Just copy The following into a .Bas module:
Just a few notes:
- A column size of 0, makes column acts as a spring.
- To set a 0 column, make it too small, but not 0 (ie. 0.1)
- The 2nd parameter just signals which property to setup
- The 1st parameter is the flex. This is declared as variant in order to accept msflexgrid and mshflexgrid.


Enum cpFlexPropType
cpeNone
cpeWidth
cpeAlignment
cpeCaption
cpeFormat
cpeRowCaption
cpeTextMatrix
End Enum

Public Sub SetupFlex(Flex, cpType As cpFlexPropType, ParamArray x() As Variant)
Dim n As Integer, i As Integer, Total As Single, SpringId As Integer

With Flex
If cpType = cpeRowCaption Then
.Rows = UBound(x) + 1
For n = 0 To (.Rows - 1)
.TextMatrix(n, 0) = x(n)
Next n
Else
If cpType = cpeCaption Then .Cols = UBound(x) + 1
For n = 0 To (.Cols - 1)
If n > UBound(x) Then Exit For
Select Case cpType
Case cpeWidth:
If x(n) = 0 Then
For i = 0 To UBound(x)
Total = Total + x(i)
If x(i) = 0 Then SpringId = i
Next
x(SpringId) = Flex.Width - Total - cScrollWidth
End If
If x(n) >= 0 Then .ColWidth(n) = x(n)
Case cpeAlignment: If x(n) >= 0 Then .ColAlignment(n) = x(n)
Case cpeCaption: .TextMatrix(0, n) = x(n)
Case cpeTextMatrix: .TextMatrix(x(0), n) = x(n + 1)
End Select
Next n
End If
End With
End Sub


Use is as follows:

SetupFlex .fgGrid, cpeCaption, "Column1!", "Column2", "Column3"
SetupFlex .fgGrid, cpeAlignment, 0, 0, 2
SetupFlex .fgGrid, cpeWidth, 1200, 0, 900


This is just post as an flexgrid addon (I have many more)


I hope this helps you,
Carlos
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top