wait for sub to complete?

marco208

Member
Joined
Jun 14, 2011
Messages
6
Programming Experience
Beginner
Hi,

i have this code:
VB.NET:
    Private Sub typendetextbouwen(ByVal texttetypen As String)
        var_Numberofchars = 0
        var_Numberofcharstyped = 0
        var_Chars = New List(Of String)
        For Each var_Char As Char In texttetypen
            var_Numberofchars += 1
            var_Chars.Add(Convert.ToString(var_Char))
        Next
        tmr_Typing.Enabled = True


    End Sub

I activate with

VB.NET:
    Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        typendetextbouwen("Hi")
        typendetextbouwen("Im Marco")


    End Sub

How to make the "Im Marco" wait? else it wont typ the first line

Thanks for reading

Greets,
Marco
 
You don't "make it wait". If you did then the application would freeze and your Timer wouldn't work anyway. You haven't even explained what it is that you're trying to do, so I suppose we have to guess. I looks like you are trying to create a list of text that will then displayed somewhere using a Timer, probably one character at a time. Is that about it? Please provide that information yourself in future posts.

Anyway, what I would suggest is that you have one queue of text to "type" and you just keep adding to that as required. Your Timer can just take the next character in the queue each Tick. If there's no data, it does nothing.

I'm using the word "queue" here on purpose, because .NET includes more than one class that behaves as a FIFO queue. They are aptly named Queue, which is non-generic, and Queue(Of T), which is generic. In your case, assuming that you are "typing" one character at a time, I'd suggest a Queue(Of Char). You can enqueue text like this:
Private charQueue As New Queue(Of Char)

Private Sub EnqueueText(text As String)
    For Each ch In text
        Me.charQueue.Enqueue(ch)
    Next
End Sub
In your Tick event handler, you can take the next character in the queue and use it however is appropriate:
If Me.charQueue.Count > 0 Then
    Dim ch = Me.charQueue.Dequeue()

    'Use ch here.
End If
There's no need to worry about synchronising the collection because you're only using one thread.
 
Thank you for answering this professional to me!

I'm sorry i reply this late, i had some things private which kept me away from the computer...

I will try this!
 
Back
Top