Home All Groups Group Topic Archive Search About
Author
15 Jun 2006 5:13 PM
Paul Anderson
I have a newbie question that I hope someone can answer.
VB Studio 2005

I have a form with a button and a listbox.  When the button is pressed
the following routine is run:

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
        Dim i As Integer
        Dim wrap As String
        wrap = Chr(13) & Chr(10)
        For i = 1 To 10
            TextBox1.Text = TextBox1.Text & "Loop " & i & wrap
            System.Threading.Thread.Sleep(1000)
        Next i
    End Sub
End Class

All this does is populate the listbox with loop1,loop2, etc with a crlf
at the end of each loopx.

While this is running I can see that the listbox is getting bigger
because the elevator bar is created and successively gets smaller as
more loops are run.  However the words ("loopx") do not appear in the
listbox until the entire 10 iterations of the loop are complete.

Can anyone tell me why this happens?  Is there a cure?  Can I make it so
that each "loopx" line appears successively once per second in the box?

Thank you.

Paul Anderson

Author
15 Jun 2006 5:57 PM
Henry
Show quote Hide quote
"Paul Anderson" <pate***@magma.ca> wrote in message
news:MK2dnUQkJLu6CAzZnZ2dnUVZ_t-dnZ2d@magma.ca...
>I have a newbie question that I hope someone can answer.
> VB Studio 2005
>
> I have a form with a button and a listbox.  When the button is pressed
> the following routine is run:
>
> Public Class Form1
>    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button1.Click
>        Dim i As Integer
>        Dim wrap As String
>        wrap = Chr(13) & Chr(10)
>        For i = 1 To 10
>            TextBox1.Text = TextBox1.Text & "Loop " & i & wrap
>            System.Threading.Thread.Sleep(1000)
>        Next i
>    End Sub
> End Class
>

Listbox, or textbox?

Protected Sub Button3_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button3.Click

Dim i As Integer

For i = 0 To 10

    ListBox1.Items.Add("text " + CStr(i))

Next i

End Sub



cheers

Henry
Author
15 Jun 2006 6:14 PM
Paul Anderson
Henry wrote:
Show quoteHide quote
> "Paul Anderson" <pate***@magma.ca> wrote in message
> news:MK2dnUQkJLu6CAzZnZ2dnUVZ_t-dnZ2d@magma.ca...
>> I have a newbie question that I hope someone can answer.
>> VB Studio 2005
>>
>> I have a form with a button and a listbox.  When the button is pressed
>> the following routine is run:
>>
>> Public Class Form1
>>    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
>> System.EventArgs) Handles Button1.Click
>>        Dim i As Integer
>>        Dim wrap As String
>>        wrap = Chr(13) & Chr(10)
>>        For i = 1 To 10
>>            TextBox1.Text = TextBox1.Text & "Loop " & i & wrap
>>            System.Threading.Thread.Sleep(1000)
>>        Next i
>>    End Sub
>> End Class
>>
>
> Listbox, or textbox?
>
> Protected Sub Button3_Click(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles Button3.Click
>
> Dim i As Integer
>
> For i = 0 To 10
>
>     ListBox1.Items.Add("text " + CStr(i))
>
> Next i
>
> End Sub
>
>
>
> cheers
>
> Henry
>
>
Henry,
    Thanks for the response but it's a textbox so items.add won't work.
The output is produced, but only after the procedure has completed.  I'd
like it to refresh while looping through the procedure.
        Paul
Author
15 Jun 2006 6:37 PM
Chris Dunaway
Paul Anderson wrote:

> like it to refresh while looping through the procedure.

Try addingt TextBox1.Refresh to the loop
Author
15 Jun 2006 6:53 PM
Paul Anderson
Chris Dunaway wrote:
> Paul Anderson wrote:
>
>> like it to refresh while looping through the procedure.
>
> Try addingt TextBox1.Refresh to the loop
>
Chris,
    Thank you.  Just what I needed.
            Paul.
Author
15 Jun 2006 6:48 PM
Terry
Your code should be:
   TextBox1.Text = TextBox1.Text & "Loop " & i & wrap
   Me.Refresh()
   System.Threading.Thread.Sleep(1000)

--
Terry


Show quoteHide quote
"Paul Anderson" wrote:

> I have a newbie question that I hope someone can answer.
> VB Studio 2005
>
> I have a form with a button and a listbox.  When the button is pressed
> the following routine is run:
>
> Public Class Form1
>     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button1.Click
>         Dim i As Integer
>         Dim wrap As String
>         wrap = Chr(13) & Chr(10)
>         For i = 1 To 10
>             TextBox1.Text = TextBox1.Text & "Loop " & i & wrap
>             System.Threading.Thread.Sleep(1000)
>         Next i
>     End Sub
> End Class
>
> All this does is populate the listbox with loop1,loop2, etc with a crlf
> at the end of each loopx.
>
> While this is running I can see that the listbox is getting bigger
> because the elevator bar is created and successively gets smaller as
> more loops are run.  However the words ("loopx") do not appear in the
> listbox until the entire 10 iterations of the loop are complete.
>
> Can anyone tell me why this happens?  Is there a cure?  Can I make it so
> that each "loopx" line appears successively once per second in the box?
>
> Thank you.
>
> Paul Anderson
>