|
-
Feb 8th, 2000, 02:50 PM
#1
Thread Starter
Lively Member
I'm trying to write a common function which sets the caption property of label arrays.
eg
On my form, I have label1(0) and label(1) and want to set the caption with 'Caption1' and 'Caption2' respectively with the following function call:
SetCaption Label1, "Caption1", "Caption2"
So how can I declare the function?
Public Sub SetCaption(LabelCtrl as ???, ParamArray Data() as Variant)
for i = 0 to ubound(data)
LabelCtrl(i).Caption = data(i)
next
End Sub
TIA
Carolyn
-
Feb 8th, 2000, 04:51 PM
#2
Frenzied Member
this works:
Code:
Option Explicit
Dim captions(4) As String
Private Sub Command1_Click()
SetCaption Label1, captions
End Sub
Private Sub Form_Load()
captions(0) = "hello"
captions(1) = "hello"
captions(2) = "hello"
captions(3) = "hello"
End Sub
Public Sub SetCaption(LabelCtrl As Variant, Data() As String)
Dim i As Integer
For i = 0 To UBound(Data) - 1
LabelCtrl(i).Caption = Data(i)
Next
End Sub
------------------
Mark Sreeves
Analyst Programmer
[email protected]
A BMW Group Company
-
Nov 26th, 2013, 08:17 AM
#3
New Member
Re: Passing control array as parameter
 Originally Posted by mark sreeves
this works:
Code:
option explicit
dim captions(4) as string
private sub command1_click()
setcaption label1, captions
end sub
private sub form_load()
captions(0) = "hello"
captions(1) = "hello"
captions(2) = "hello"
captions(3) = "hello"
end sub
public sub setcaption(labelctrl as variant, data() as string)
dim i as integer
for i = 0 to ubound(data) - 1
labelctrl(i).caption = data(i)
next
end sub
------------------
mark sreeves
analyst programmer
[email protected]
a bmw group company
yahooo!!!! You saved me!!!!!!
-
Nov 26th, 2013, 09:28 AM
#4
Re: Passing control array as parameter
Another solution to a 13 year old unresolved problem:
Code:
Private Sub SetCaptions(ByVal LabelArray As Object, ParamArray Captions() As Variant)
Dim i As Integer, LB As Integer, UB As Integer
LB = LabelArray.LBound
UB = LabelArray.UBound
If LB = LBound(Captions) Then
If UB <= UBound(Captions) Then
On Error Resume Next
For i = LB To UB
LabelArray(i).Caption = Captions(i)
Next
End If
End If
End Sub
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|