Results 1 to 10 of 10

Thread: TypeWriter Effect (code included in post)

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2003
    Posts
    34

    TypeWriter Effect (code included in post)

    its pretty simple and staight forward so here it is:

    VB Code:
    1. Private Declare Function GetTickCount Lib "kernel32" () As Long
    2.  
    3. Public Sub TypeWriter(txtt As TextBox, time As Single, text As String)
    4. '^^^ for time you put the amount of seconds you want it to wait
    5. Dim progress As Integer
    6. Dim lastc As Long
    7.  
    8. progress = 1
    9. lastc = GetTickCount
    10. time = time * 1000
    11.  
    12. Do While progress <> (Len(text) + 1)
    13. If GetTickCount - lastc > time Then
    14. txtt.text = txtt.text + Mid(text, progress, 1)
    15. txtt.Refresh
    16. progress = progress + 1
    17. lastc = GetTickCount
    18. End If
    19. DoEvents
    20. Loop
    21.  
    22. End Sub
    23.  
    24. Private Sub Form_Load()
    25. Me.Show
    26. TypeWriter Text1, 0.5, "Welcome"
    27. End Sub
    a 17 year old kid who has nothing better to do !
    and i never said i was right !!!

  2. #2
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    Nice one, i tried putting it into a label, but that wont display it properly. (even with a timer, and refresh). Is there anyway of putting it into a label?

    Suppose i could just make the text box flat, and set focus to another control (to hide the | cursor position)

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2003
    Posts
    34
    for a label change the declaration to:

    VB Code:
    1. Public Sub TypeWriter(txtt As Label, time As Single, text As String)
    2. ''^^^ make it a label instead of a textbox
    and then change the .text property to caption:

    VB Code:
    1. txtt.Caption = txtt.Caption & Mid(text,progress,1)
    a 17 year old kid who has nothing better to do !
    and i never said i was right !!!

  4. #4
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    Yeah, im not daft - tried that. But it aint going to animate (or add text) to the label cos it needs updating. Im not bothered though

  5. #5

    Thread Starter
    Member
    Join Date
    Sep 2003
    Posts
    34
    This code works fine for me with a label:

    VB Code:
    1. Private Declare Function GetTickCount Lib "kernel32" () As Long
    2.  
    3. Public Sub TypeWriter(txtt As Label, time As Single, text As String)
    4. '^^^ for time you put the amount of seconds you want it to wait
    5. Dim progress As Integer
    6. Dim lastc As Long
    7.  
    8. progress = 1
    9. lastc = GetTickCount
    10. time = time * 1000
    11.  
    12. Do While progress <> (Len(text) + 1)
    13. If GetTickCount - lastc > time Then
    14. txtt.Caption = txtt.Caption + Mid(text, progress, 1)
    15. txtt.Refresh
    16. progress = progress + 1
    17. lastc = GetTickCount
    18. End If
    19. DoEvents
    20. Loop
    21.  
    22. End Sub
    23.  
    24. Private Sub Form_Load()
    25. Me.Show
    26. TypeWriter Label1, 0.5, "Welcome"
    27. End Sub
    a 17 year old kid who has nothing better to do !
    and i never said i was right !!!

  6. #6
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    Just realized , i was using a third party ocx label, which doesnt use .Caption but .Label as the text appearance. Thanks again!

  7. #7
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    Im making a app called "VB Code Library" which has loads of API,codes,links,tips,snippets & tutorials. I was wondering if i could include your code into the library?

  8. #8
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    Heres an early development screenshot!
    Attached Images Attached Images  

  9. #9

    Thread Starter
    Member
    Join Date
    Sep 2003
    Posts
    34
    sure you can use this code or modify anyway you want. have fun with it !
    a 17 year old kid who has nothing better to do !
    and i never said i was right !!!

  10. #10
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    Ok thanks dude

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