Results 1 to 4 of 4

Thread: Visual Basic - The Best Typewriting Code!

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    4

    Visual Basic - The Best Typewriting Code!

    Code:
    'Virtually the best typewriting code available.
    'All others i have seen are much longer.
    'I am now currently working on a "wait" function
    'so there is no need for a timer.
    
    Private Sub Timer1_Timer()
    Typewrite "Testing"
    End Sub
    
    Private Function Typewrite(Word As String)
    'Function Simply Processes Effect Of A Typewriter.
    Static NextChar As Integer 'Move onto the next character.
    Dim Length As Integer 'Used for increasing length.
    Dim Display As String 'Letters to display.
    NextChar = NextChar + 1 'Move onto the next letter.
    Length = Length + 1 'Increase the length of the word.
    Display = Mid$(Word, NextChar, Length) 'What to display.
    Label1.Caption = Label1.Caption & Display 'Display!
    End Function
    If anyone has any ideas how to include a wait function then please offer me your opinions.

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Visual Basic - The Best Typewriting Code!

    Originally posted by vb Legend
    Code:
    'Virtually the best typewriting code available.
    'All others i have seen are much longer.
    'I am now currently working on a "wait" function
    'so there is no need for a timer.
    
    Public sub Typewrite(byval strWord As String, byval dteDelayFor as date)
    'Function Simply Processes Effect Of A Typewriter.
     Dim dteDisp as Date 'DateTime to disp after
     Dim lngCtr as long
    
      for lngCtr = 0 to len(strWord)
          Label1.Caption = mid$(strWord,1,lngCtr)
          dteDisp = now + dteDelay
          do until now>dteDisp
             ' Delay around here
          loop
      next
    End sub
    This sort of works, but not brilliantly. Probably need the gettickcount api call to get a more accurate time.
    To run :
    TypeWrite "Testing",Cdate("0:0:01")


    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    4
    A nice way to configure the delay.

    Im just re-arranging it so that it delays between each letter appearing.

    The reason why i am doing these basic code's is because i am currently working on a module file, that is an archive of functions that people can use. Im just gonna keep adding simple functions and subs similar to this one.



    Last edited by vb Legend; Jul 15th, 2004 at 09:38 AM.

  4. #4
    Fanatic Member
    Join Date
    Dec 2002
    Location
    North Carolina
    Posts
    734
    VB Code:
    1. Private Declare Function GetTickCount Lib "kernel32" Alias "GetTickCount" () As Long
    2.  
    3. Private Sub Wait ( msDelay as Long )
    4.  
    5.      Dim lngLastTick as Long
    6.  
    7.      lngLastTick = GetTickCount
    8.  
    9.      Do While (lngLastTick + msDelay) >= GetTickCount
    10.      Loop
    11.  
    12. End Sub
    You should add a doevents inside the do while loop if you want your program not to be "frozen"

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