[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
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
Re: Its there A way to make this code work with .captions?
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
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:
Option Explicit
Private sTypeWriteText As String
Private lTypeWriter As Long
Private Sub Form_Load()
Timer1.Enabled = False
Timer1.Interval = 60
Me.Show
DoEvents
ExecTypeWriter "Text text"
End Sub
Public Sub ExecTypeWriter(ByVal DisplayText As String)
If Timer1.Enabled Then Exit Sub 'prevents the execution while the timer already displaying a text..
lTypeWriter = 0
sTypeWriteText = DisplayText
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
lTypeWriter = lTypeWriter + 1
If lTypeWriter > Len(sTypeWriteText) Then Timer1.Enabled = False: Exit Sub
Picture1.Cls
Picture1.Print Left$(sTypeWriteText, lTypeWriter);
End Sub
1 Attachment(s)
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.
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.
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:
Option Explicit
Private oTypeWriterObj As Object
Private sTypeWriteText As String
Private lTypeWriter As Long
Private Sub Form_Load()
Timer1.Enabled = False
Timer1.Interval = 60
Me.Show
DoEvents
ExecTypeWriter "Text text", Me
End Sub
Public Sub ExecTypeWriter(ByVal DisplayText As String, ByRef OnObjectCaption As Object)
If Timer1.Enabled Then Exit Sub 'prevents the execution while the timer already displaying a text..
lTypeWriter = 0
Set oTypeWriterObj = OnObjectCaption
oTypeWriterObj.Caption = ""
sTypeWriteText = DisplayText
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
lTypeWriter = lTypeWriter + 1
If lTypeWriter > Len(sTypeWriteText) Then Timer1.Enabled = False
oTypeWriterObj.Caption = Left$(sTypeWriteText, lTypeWriter)
End Sub
Quote:
check the .exe attachment i uploaded.
Dont upload executables, it is against the rules of vbforums.
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
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.