Results 1 to 10 of 10

Thread: [RESOLVED] Its there A way to make this code work with .captions?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Posts
    111

    Resolved [RESOLVED] Its there A way to make this code work with .captions?

    Hello there, i have this code that mimic a type-Writer effect using the Picturebox, but this doesn't work with .caption =(label1.caption, form1.caption etc.) is give a error that doesn't support this method or something like that.

    How can i make this to work with .captions? thanks

    Code:
    
    Private Sub Form_Load()
    Timer1.Enabled = 0
    Timer1.Interval = 60
    
    Timer1.Enabled = 1
    End Sub
    
    Private Sub Timer1_Timer()
    Static I&
    I = I + 1
    
    If I > Len("text Text") Then
         'Picture1.Cls
         Timer1.Enabled = 0
         'I = 0
    End If
    
    Picture1.Print Mid("text ext", I, 1);
    
    End Sub
    

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Its there A way to make this code work with .captions?

    can you show how you tried to use .Caption? Not everything supports the caption property... in fact, I think only Labels do.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Its there A way to make this code work with .captions?

    Labels and Forms.

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Its there A way to make this code work with .captions?

    Code:
    Option Explicit
    Private Sub Form_Load()
    Timer1.Enabled = 0
    Timer1.Interval = 60
    
    Timer1.Enabled = 1
    End Sub
    
    Private Sub Timer1_Timer()
    Static I&
    I = I + 1
    
    If I > Len("text Text") Then
         'Picture1.Cls
         Timer1.Enabled = 0
         'I = 0
    End If
    
    Me.Print Mid("text ext", I, 1);
    'or
    Label1.Caption = ""
    Label1.Caption = Label1.Caption & Mid("text ext", I, 1)
    
    End Sub

  5. #5
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    Re: Its there A way to make this code work with .captions?

    This will make you the typewriter effect. Just call the public sub, ExecTypeWriter, anytime you want to display a new text.

    vb Code:
    1. Option Explicit
    2. Private sTypeWriteText As String
    3. Private lTypeWriter As Long
    4.  
    5. Private Sub Form_Load()
    6.   Timer1.Enabled = False
    7.   Timer1.Interval = 60
    8.   Me.Show
    9.   DoEvents
    10.  
    11.   ExecTypeWriter "Text text"
    12. End Sub
    13.  
    14. Public Sub ExecTypeWriter(ByVal DisplayText As String)
    15.   If Timer1.Enabled Then Exit Sub 'prevents the execution while the timer already displaying a text..
    16.   lTypeWriter = 0
    17.   sTypeWriteText = DisplayText
    18.   Timer1.Enabled = True
    19. End Sub
    20.  
    21. Private Sub Timer1_Timer()
    22.   lTypeWriter = lTypeWriter + 1
    23.  
    24.   If lTypeWriter > Len(sTypeWriteText) Then Timer1.Enabled = False: Exit Sub
    25.   Picture1.Cls
    26.   Picture1.Print Left$(sTypeWriteText, lTypeWriter);
    27. End Sub

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Posts
    111

    Re: Its there A way to make this code work with .captions?

    Quote Originally Posted by MartinLiss
    Code:
    Option Explicit
    Private Sub Form_Load()
    Timer1.Enabled = 0
    Timer1.Interval = 60
    
    Timer1.Enabled = 1
    End Sub
    
    Private Sub Timer1_Timer()
    Static I&
    I = I + 1
    
    If I > Len("text Text") Then
         'Picture1.Cls
         Timer1.Enabled = 0
         'I = 0
    End If
    
    Me.Print Mid("text ext", I, 1);
    'or
    Label1.Caption = ""
    Label1.Caption = Label1.Caption & Mid("text ext", I, 1)
    
    End Sub
    Thast the problem, when using the .caption doesn't append the oder characters, only show one character at a time(show one then clear then show the next character etc.)

    check the .exe attachment i uploaded. i want to do the same effect that this program do in the Form Caption.
    Attached Files Attached Files

  7. #7
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Its there A way to make this code work with .captions?

    I stuck the Label1.caption = "" line at the last minute and that's the cause of my code not working. Remove that line and if needed put it someplace else.

  8. #8
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    Re: Its there A way to make this code work with .captions?

    This will support the Captions. You can call the ExecTypeWriter() for any form, or labels that have the caption property.

    for example:

    Call ExecTypeWriter("Text text", Form1)

    or

    Call ExecTypeWriter("Text text", Label1)


    vb Code:
    1. Option Explicit
    2. Private oTypeWriterObj As Object
    3. Private sTypeWriteText As String
    4. Private lTypeWriter As Long
    5.  
    6. Private Sub Form_Load()
    7.   Timer1.Enabled = False
    8.   Timer1.Interval = 60
    9.   Me.Show
    10.   DoEvents
    11.  
    12.   ExecTypeWriter "Text text", Me
    13. End Sub
    14.  
    15. Public Sub ExecTypeWriter(ByVal DisplayText As String, ByRef OnObjectCaption As Object)
    16.   If Timer1.Enabled Then Exit Sub 'prevents the execution while the timer already displaying a text..
    17.   lTypeWriter = 0
    18.  
    19.   Set oTypeWriterObj = OnObjectCaption
    20.   oTypeWriterObj.Caption = ""
    21.  
    22.   sTypeWriteText = DisplayText
    23.   Timer1.Enabled = True
    24. End Sub
    25.  
    26. Private Sub Timer1_Timer()
    27.   lTypeWriter = lTypeWriter + 1
    28.  
    29.   If lTypeWriter > Len(sTypeWriteText) Then Timer1.Enabled = False
    30.   oTypeWriterObj.Caption = Left$(sTypeWriteText, lTypeWriter)
    31. End Sub

    check the .exe attachment i uploaded.
    Dont upload executables, it is against the rules of vbforums.
    Last edited by Jim Davis; Nov 26th, 2008 at 02:49 PM.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Posts
    111

    Re: Its there A way to make this code work with .captions?

    Quote Originally Posted by MartinLiss
    I stuck the Label1.caption = "" line at the last minute and that's the cause of my code not working. Remove that line and if needed put it someplace else.
    Yep, that was the problem, now works for any .captions.Thanks

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Posts
    111

    Re: Its there A way to make this code work with .captions?

    Quote Originally Posted by Jim Davis


    Dont upload executables, it is against the rules of vbforums.
    Ok, and thanks for the code.

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