Array Control Problem

jerome_gail26
09-16-2009, 07:34 PM
I have a method place on a module which require Flexgrid and a control.
Now the problem is when i call this method i got error Type Mismatch and highlight
searcher2 MSFlexGrid1, cmbSearch

On Module:

Public Sub searcher2(Flex As MSFlexGrid, _
NameOfControl As Control)
'some code
End Sub

On Form1:

Private Sub cmbSearch_Change(Index As Integer)
searcher2 MSFlexGrid1, cmbSearch
End Sub


This is to update my post on tech discussion:
http://www.xtremevbtalk.com/showthread.php?p=1341995#post1341995


Thanks,
Jerome and Gail

vb5prgrmr
09-16-2009, 08:54 PM
searcher2 MSFlexGrid1, cmbSearch(0)




Good Luck

jerome_gail26
09-16-2009, 11:16 PM
thanks for your reply but i got error msg
Must specify index of object array.

and highlights
LenUI = Len(NameOfControl(iCol).Text) 'Get the length of user input (UI)

This is the whole Searcher2 method.
Public Sub searcher2(Flex As MSFlexGrid, NameOfControl As Control)
'On Error Resume Next
Dim ROW_HEIGHT As Long
ROW_HEIGHT = IIf(Flex.RowHeight(0) > 100, Flex.RowHeight(0), 345)

For iRow = 0 To Flex.Rows - 1
For iCol = 0 To Flex.Cols - 1
'**********************************************************
'I already try to put debug.print NameOfControl(iCol).text
'but i receive same error msg.
'**********************************************************
LenUI = Len(NameOfControl(iCol).Text) 'Get the length of user input (UI)
If Left(StrConv(Flex.TextMatrix(iRow, iCol), vbLowerCase), LenUI) = _
Left(StrConv(NameOfControl(iCol).Text, vbLowerCase), LenUI) Then
Flex.RowHeight(i) = ROW_HEIGHT
Else
Flex.RowHeight(i) = 0
Exit For 'No need to check other columns
End If
Next
Next
End Sub

Thanks

vb5prgrmr
09-17-2009, 07:17 AM
Add a parameter that accepts the index...



Good Luck

jerome_gail26
09-17-2009, 08:25 PM
I Try it to put ()
searcher2(Flex As MSFlexGrid, NameOfControl() As Control)

but another error msg:

Compile ERROR:
Type Mismatch: Array or User-define type expected.



Thanks

vb5prgrmr
09-18-2009, 06:11 AM
If you put that then you don't include the index as I previously showed.



Good Luck

jerome_gail26
09-21-2009, 07:03 PM
Thanks for your replies but I actually do not know how to add paramater that accepts the index. searcher2 is place on module. So far this is what i have tried.


Public Sub searcher2(Flex As MSFlexGrid, NameOfControl As Control)
'On Error Resume Next
Dim NewControl(0 To 100) As ComboBox
Set NewControl(icol) = NameOfControl
Dim ROW_HEIGHT As Long
ROW_HEIGHT = IIf(Flex.RowHeight(0) > 100, Flex.RowHeight(0), 345)
For iRow = 0 To Flex.Rows - 1
Debug.Print "ROW " & iRow
For icol = 0 To Flex.Cols - 1
'''''''''*****Set NewControl(icol) = NameOfControl
Debug.Print NewControl(icol).Text
LenUI = Len(NewControl(icol).Text) 'Get the length of user input (UI)
If Left(StrConv(Flex.TextMatrix(iRow, icol), vbLowerCase), LenUI) <> _
StrConv(NewControl(icol).Text, vbLowerCase) Then
Flex.RowHeight(iRow) = 0
Exit For 'No need to check other columns
Else
Flex.RowHeight(iRow) = 345
End If
Next
Next
End Sub

Now new error msg occured

Object variable or with block variable not set


I understand that i have to put Set NewControl(icol) = NameOfControl before inside the second For...Next statement but it still give the cmbSearch(0) to NewColtrol(1).
What i am trying is :

cmbSearch(0) = NewColtrol(0)
cmbSearch(1) = NewColtrol(1)
cmbSearch(2) = NewColtrol(2)
cmbSearch(3) = NewColtrol(3)
and so on.

Thanks again,
Jerome and Gail

vb5prgrmr
09-21-2009, 10:57 PM
Okay, I have reread this and the original thread...

So, your latest problem is that you have an array of combo boxes from 0 to x and you want to be able to reference those combo boxes with a generic control array variable, and where you are having problems with is that when you pass in Combo1(0), it is being set to GenericControlVariable(1)...

Your problem is with the variable "icol". I do not see where it is defined nor do I see where it is incremented. So what it seems to me what is happening is...

ComboCount = 0
icol = icol + 1
Call whatever(Combo1(ComboCount))

Sub whatever(ControlToAddToGenericArray As Control)
Dim GenericControlArrayVariable(0 To 100) As ComboBox
Set GenericControlArrayVariable(icol) = ControlToAddToGenericArray


Okay, there are several things wrong with this coding...

First, it seems that you are incrementing the icol variable before you pass in the single referenced combo box and thus new(1) = Old(0)

Then I see, Dim NewControl(0 To 100) As ComboBox, which makes me think that you want to pass in the entire array of combo boxes so passing Combo1(0) defeats this purpose but your NameOfControl As Control will only accept a single control, hence I believe the confusion upon my part.

So If you are wanting to pass in the entire control array of existing combo boxes then you would need to do this....

'in this example we have three combo boxes (combo1(0 to 2)
Dim C(0 to 2) As ComboBox
Set C(0) = Combo1(0)
Set C(1) = Combo1(1)
Set C(2) = Combo1(2)

Call PassingAControlArray(C)

'...

Private Sub PassingAControlArray(C() As ComboBox) 'not control

End Sub


Which pretty much defeats the purpose of needing Dim NewControl(0 to 100) As ComboBox.

However, you can change the above to...

Dim C(0 to 2) As Control
Set C(0) = Combo1(0)
Set C(1) = Combo1(1)
Set C(2) = Combo1(2)

Call PassingAControlArray(C)

'...

Private Sub PassingAControlArray(C() As Control)

End Sub


if you wish but still it defeats the purpose of defining NewControl as you are passing in the array already.


Whew! I hope that helps some...


Good Luck

kassyopeia
09-22-2009, 01:02 AM
I've only read the last post in full, so I don't know if this is helpful, but IIRC it is possible to pass the control array itself if that is what is wanted:

Call PassingAControlArray(Combo1)

'...

Private Sub PassingAControlArray(C As Object)

End Sub

One just has to work without intellisense in the sub.

jerome_gail26
09-22-2009, 06:48 PM
vb5prgrmr,

Your problem is with the variable "icol". I do not see where it is defined nor do I see where it is incremented.


"icol" is not defined, however i use For...Next Statement so automatically add 1(base on my understanding).


First, it seems that you are incrementing the icol variable before you pass in the
single referenced combo box and thus new(1) = Old(0)

I did not define iCol nor give any value to it so definitely it will give Zero(0) on first.


Then I see, Dim NewControl(0 To 100) As ComboBox, which makes me think that
you want to pass in the entire array of combo boxes so passing Combo1(0) defeats
this purpose but your NameOfControl As Control will only accept a single control,
hence I believe the confusion upon my part.

As what i have told you, i am not familiar with control array so i tried and tried and came up that code base on your post #4. But i must admit that is my mistake. I am sorry if that make you confuse, maybe some of my english is bad which makes my explanation bad... hehehe :)

But still Thank You with your help.

kassyopeia,
Thank you. That is what i am looking for. It is now working. :)

Thanks Again,
Jerome and Gail

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum