Results 1 to 3 of 3

Thread: [resolved]Use anything that has .caption

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    343

    Resolved [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:
    1. Option Explicit
    2.  
    3. Dim i As Integer
    4. Dim Start As Long
    5. Dim EndT As Long
    6. Dim Total As Double
    7. Dim DoTime As Integer
    8.    
    9. Declare Function GetTickCount Lib "kernel32" () As Long
    10.  
    11. Public Function TimerStart(Optional Lbl As Label, _
    12. Optional Cmd As CommandButton, _
    13. Optional Frm As Form) As Long
    14.  
    15.     i = i + 1
    16.        
    17.     If i = 1 Then
    18.         Start = GetTickCount
    19.     End If
    20.        
    21.     EndT = GetTickCount
    22.     Total = (EndT - Start) / 1000
    23.  
    24.         Cmd.Caption = Total
    25.  
    26.         Lbl.Caption = Total
    27.  
    28.         Frm.Caption = Total
    29.  
    30. End Function
    31.  
    32. Public Function TimerReset()
    33.     i = 0
    34. 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.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    343

    Re: Use anything that has .caption

    Thanks, that did it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width