|
-
Mar 22nd, 2008, 02:30 PM
#1
Thread Starter
Hyperactive Member
[resolved]Use anything that has .caption
Hello, I was wondering, I have a function and I want the user to enter a control they have (label, form, commandbutton, anything that can do .caption). But I don't know how I can do this...
Module:
vb Code:
Option Explicit
Dim i As Integer
Dim Start As Long
Dim EndT As Long
Dim Total As Double
Dim DoTime As Integer
Declare Function GetTickCount Lib "kernel32" () As Long
Public Function TimerStart(Optional Lbl As Label, _
Optional Cmd As CommandButton, _
Optional Frm As Form) As Long
i = i + 1
If i = 1 Then
Start = GetTickCount
End If
EndT = GetTickCount
Total = (EndT - Start) / 1000
Cmd.Caption = Total
Lbl.Caption = Total
Frm.Caption = Total
End Function
Public Function TimerReset()
i = 0
End Function
Basically my question is.. how can I get cmd.caption=total, lbl.caption=total etc. into just one. Example: obj.caption=total. Thanks.
I wasn't quiet sure how to ask this, I hope it wasn't too confusing.
Last edited by bluehairman; Mar 22nd, 2008 at 06:14 PM.
-
Mar 22nd, 2008, 03:33 PM
#2
Re: Use anything that has .caption
By using error checking and enumerating controls this can be done relatively easily. Modify the following to suit your needs. Note that the routine expects a parent level object, so pass the Form.
Code:
Private Sub ChangeCaptions(theObject As Object, byval newCaption As String)
On Error Resume Next ' required; not all controls have caption property
Dim vCtrl As Control
For Each vCtrl In theObject
vCtrl.Caption = newCaption
Next
theObject.Caption = newCaption
If Err Then Err.Clear
End Sub
Private Sub Command1_Click()
ChangeCaptions Form1, "Hi There"
End Sub
-
Mar 22nd, 2008, 06:14 PM
#3
Thread Starter
Hyperactive Member
Re: Use anything that has .caption
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
|