Referencing code syntax 
Author Message
 Referencing code syntax

Hello,
    In all actuality it seems with your naming that is what you are using is
a control array with out the array.  The only way I have found to do what
you want is an array.  I also have learned to enjoy some control arrays do
to the fact that then I just have on change event for the whole array and
then reference different code for the different instances by using the
"index" of each.  To me this makes editing code and reading it easier due to
that they are in one area.  I do not know your reasoning against control
arrays although they do come in handy in certain circumstances.

HTH,
Lorrin L. Williams
Karma Komputing

Quote:

>I have two button controls on the form called:
>    cmdAppButtons1
>    cmdAppButtons2

>I want to reference them in code by just altering the last value
>    ("cmdAppButtons" & "1").Top = 100
>    ("cmdAppButtons" & "2").Top = 100

>Would anyone know the correct syntax to do this, or isn't it possible.
>I dont want to use control arrays.

>Thanks in advance,
>    Travis Penglase.



Fri, 10 Nov 2000 03:00:00 GMT  
 Referencing code syntax

Quote:

> I have two button controls on the form called:
>     cmdAppButtons1
>     cmdAppButtons2

> I want to reference them in code by just altering the last value
>     ("cmdAppButtons" & "1").Top = 100
>     ("cmdAppButtons" & "2").Top = 100

> Would anyone know the correct syntax to do this, or isn't it possible.
> I dont want to use control arrays.

I guess I cant think of a situation where a control array, isnt a good idea
for puting several similar controls on one form.  But, since you're in
control.... :)

You might try assigning the buttons to a collection with their names as
keys:

colMyButtons.Add cmdAppButtons1, "cmdAppButtons1"
colMyButtons.Add cmdAppButtons2, "cmdAppButtons2"

Then:

colMyButtons("cmdAppButtons" & "1").Top = 100
colMyButtons("cmdAppButtons" & "2").Top = 100

LFS



Fri, 10 Nov 2000 03:00:00 GMT  
 Referencing code syntax

Travis-
        It seems that everyone wants to do
this lately. Here's one very inefficient way to
do it. It is about 10 times easier to just use a
control array, though. ( IMHO )

Joe
________snip___________________________
Option Explicit

Private Sub Form_Load()
    Dim i As Integer
    Dim ctl As Control
    For i = 1 To 2
        For Each ctl In Controls
            If ctl.Name = "cmdAppButtons" & CStr(i) Then
                ctl.Top = 100 * i
                ctl.Left = 1000 * i
            End If
        Next ctl
    Next i
End Sub
_____snip___________________________________
--
***********************************************************

Microsoft Developer MVP- Visual Basic
VB geek at large. (Well, not that large!)
"He preaches well that lives well, quoth Sancho; that's
all the divinity I understand." Miguel de Cervantes
**********************************************************
PS- Please reply to the newsgroup- except in the
case of flames, insults, etc. (Don't bother.)



Quote:
> I have two button controls on the form called:
>     cmdAppButtons1
>     cmdAppButtons2

> I want to reference them in code by just altering the last value
>     ("cmdAppButtons" & "1").Top = 100
>     ("cmdAppButtons" & "2").Top = 100

> Would anyone know the correct syntax to do this, or isn't it possible.
> I dont want to use control arrays.

> Thanks in advance,
>     Travis Penglase.



Fri, 10 Nov 2000 03:00:00 GMT  
 Referencing code syntax

Quote:

>I have two button controls on the form called:
>    cmdAppButtons1
>    cmdAppButtons2
>I want to reference them in code by just altering the last value
>    ("cmdAppButtons" & "1").Top = 100
>    ("cmdAppButtons" & "2").Top = 100
>Would anyone know the correct syntax to do this, or isn't it possible.
>I dont want to use control arrays.

Try:
strIndex="1"
Me.Controls("cmdAppButtons" & strIndex).Top=100

What have you got against control arrays?



Fri, 10 Nov 2000 03:00:00 GMT  
 Referencing code syntax

Thanks for the comments. It's working!

I dont have anything against control arrays as I use them often. My routine
actually required them, but I didn't include this information in the
previous post becuase I didn't want to confuse the issue.

Anyway, routine works great.
Sample code below...

For nBatchNum = 1 to 5
    sControlName = "cmdAppButtons" & nBatchNum
    Load .Controls(sControlName)(A) 'Create New Object

    .Controls(sControlName)(A).Top = 100
    .Controls(sControlName)(A).Left = 200
 Next nBatchNum

Travis Penglase.



Mon, 13 Nov 2000 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Referencing code syntax

2. syntax to reference to subform in vba code????

3. Referencing object in form in code / Subform reference problem in code

4. Syntax for referencing the first row from a recordset in an If Then statement

5. Syntax for referencing a table column

6. Syntax and function reference

7. SQL Syntax reference?

8. Q: Reference variable in FindFirst syntax?

9. Reference to the SQL syntax used in DAO engine

10. Syntax to reference next record

11. Syntax to create reference to active Excel workbook

12. What is the syntax for referencing a form via a string

 

 
Powered by phpBB® Forum Software