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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Control Array functionality?

Status
Not open for further replies.

VictoryHighway

Technical User
Mar 4, 2004
115
US
Hello,
Does anyone if if there is a way to duplicate the VB 6 control array functionality in Access 2000?

I need to have 256 label controls that a user can click on to select a color. Obviously, in VB6 this would be a snap.

Thanks for any help.

--Geoffrey
 
No, controlarrays, as in VB6, doesn't exist in Access, as far as I know. The workaround is using a naming convention (lbl1, lbl2,... lbln), and loop them.

There's a sample here faq702-5010, section 5.

You mention "click on labels", though non attached labels have on click events, I don't think you can't determine which label was clicked through for instance the ActiveControl property, so you'd probably need to pass the label name (number) per each eventhandler, or convert to text controls, should such functionality be necessary.

Another question, though I haven't used it, I'm sure there are colour pickers around, or methods to call the inbuilt colour picker. Wouldn't that be easier than building it all yourself?

Roy-Vidar
 
Hi RoyVidar.

VictoryHighway - As indicated, you cannot have a control array, but you can have an array of controls although you have manage it yourself. Another alternative is to build a custom class which wraps the control and handles the events. Then you can have an array of those classes and it does require a little effort, but you achieve the functionality of a control array.

With respect to a color picker, that can be done without a control array or alternative. You can use one of the Windows built-in common dialogs as in the following example. In a code module, add the following type structure and API declaration.
Code:
Good Luck
--------------
To get the most from your Tek-Tips experience, please read FAQ181-2886
[i]As a circle of light increases so does the circumference of darkness around it. - Albert Einstein[/i]
 
As I was say, in a code module, add the following type structure and API declaration:
Code:
Public Type SELECTCOLOR
   tLng_StructSize           As Long
   tLng_hWndOwner            As Long
   tLng_hInstance            As Long
   tLng_RGBResult            As Long
   tStr_CustColors           As String
   tLng_Flags                As Long
   tLng_CustData             As Long
   tLng_Hook                 As Long
   tStr_TemplateName         As String
End Type

Public Declare Function ChooseColor Lib "comdlg32.dll" Alias "ChooseColorA" (pChoosecolor As SELECTCOLOR) As Long
Now on a form, add a button called 'cmdColor', and add the following code in it's Click event.
Code:
Private Sub cmdColor_Click()

   Dim lInt_Idx                     As Integer
   Dim lByt_CustomColors_Arr(64)    As Byte
   Dim lTyp_SelColor                As SELECTCOLOR
   Dim lLng_SelectedColor           As Long

   For lInt_Idx = 0 To 64
      lByt_CustomColors_Arr(lInt_Idx) = 0
   Next lInt_Idx

   With lTyp_SelColor
      .tLng_StructSize = Len(lTyp_SelColor)
      .tLng_hWndOwner = Me.hwnd
      .tLng_hInstance = 0
      .tStr_CustColors = StrConv(lByt_CustomColors_Arr, vbUnicode)
      .tLng_Flags = 0
   End With
    
   If (ChooseColor(lTyp_SelColor) <> 0) Then
      lLng_SelectedColor = lTyp_SelColor.tLng_RGBResult
      fByt_CustomColors_Arr = StrConv(lTyp_SelColor.tStr_CustColors, vbFromUnicode)
      cmdColor.ForeColor = lLng_SelectedColor
   End If
   
End Sub
In this example, the button's text color is set to the selected color, but you can use that as you need. You will also notice the CustomColors byte array. That is is keep track of chosen custom colors, and although it is not in this example, that information can easily be maintained in a table for further use.

Good Luck
--------------
To get the most from your Tek-Tips experience, please read FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Hi again CajunCenturion!

It is nice to see you back in these fora!

Got some minor trouble with regards to the byte array. Are you using two different byte arrays? To use the same byte array, I tried the following:

[tt]Dim lByt_CustomColors_Arr() As Byte
ReDim lByt_CustomColors_Arr(64)[/tt]

Which worked, else it complained with a compile error at

[tt]lByt_CustomColors_Arr = StrConv(lTyp_SelColor.tStr_CustColors, vbFromUnicode)
' Can't assign to array[/tt]

One of the thing's I've played a little with, but not used, is Terry Kreft/Stephen Lebans version from Calling Windows Choose Color Dialog, which also includes the Font Dialog.

Roy-Vidar
 
Hello Everyone!

Thanks for your input on this. I already knew that I could call the API to display the standard Windows color chooser window.

However, the reason that I wanted to write my own is because I wanted to reduce the dependency for external DLL's. One of the users of this database reported an ActiveX problem to me, even though he had the Microsoft Common Dialog Control installed and registered. So, I decided to make my own form(s) in Access to do the same thing without having to use an external module.

Again, thanks for your help.

Sincerely,
Geoffrey Aldrich
 
Good catch RoyVidar. I did not intend to use two different byte arrays, but because of the typo (fByt - lByt) I did end up using two because the fByt array is declared elsewhere for a slightly different purpose.

VictoryHighway - Given the intention not to use an external DLL, or ActiveX (which rules out using a Rich Text Box), and further compounded by the limit of the number of controls on a form, I think I might consider a different approach. I would build an image that contains 256 color blocks, each with identical size. I would then place that image on a command button and use the 'mouse up' event obtain the mouse coordinates of the click to see on which color block of the image the click took place.

Good Luck
--------------
To get the most from your Tek-Tips experience, please read FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
How are ya VictoryHighway . . . . .

[blue] CajunCenturion . . . an honor to see you![/blue]

I've used the [purple]Common Dialog ActiveX Control[/purple] (Color Dialog specific) quite a bit since Access 2K and have never had a problem. It comes with every version since 2K which alleviates portability.

I suspect it simply [blue]may not have been setup properly[/blue] and suggesting, fixing the problem would save you alot of work!

But its your call . . . . .

Calvin.gif
See Ya! . . . . . .
 
AceMan,
Honestly, it's easier for me to change how my database works than to get IT of their ... to fix an Access installation on someone's computer.

I've also scaled down the color choices to 48 (which are the same colors as in the Windows standard color picker). Also, I've added a Custom Color picker form which allows users to click UP and DOWN buttons for Red, Green and Blue. That seems to work well also.

Thanks for your help.

--Geoffrey
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top