|
-
Jul 15th, 2004, 08:27 AM
#1
Thread Starter
New Member
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.
-
Jul 15th, 2004, 08:57 AM
#2
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
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...
-
Jul 15th, 2004, 09:34 AM
#3
Thread Starter
New Member
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.
-
Jul 15th, 2004, 11:26 AM
#4
Fanatic Member
VB Code:
Private Declare Function GetTickCount Lib "kernel32" Alias "GetTickCount" () As Long
Private Sub Wait ( msDelay as Long )
Dim lngLastTick as Long
lngLastTick = GetTickCount
Do While (lngLastTick + msDelay) >= GetTickCount
Loop
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|