View Data in Textbox

J

John Smith

I have a form doing a large process. While this form is doing its
processing I want to write a status to a Textbox of where it is at in the
process. Similar to having a log file but within a textbox. As it reaches
its mark it adds a line to the textbox "Step 2 is complete." or "Step 3
Failed because of...". My problem is that the text within the textbox does
not display until after all of the processing is complete. How can I get
the text to display when it reaches each specific process? Thanx in advance
 
C

Chris, Master of All Things Insignificant

Two ways. one and simple way is to use Application.DoEvents() after you
update the text box but a lot of people say to avoid using that function.
The more complicated way is to use threading to do the processing in a
seperate thread from the UI.

Chris
 
C

Cor Ligthert

John,

You mean something as this
\\\
Private Sub Form1_Activated(ByVal sender _
As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
For i As Integer = 1 To 100000000
If i Mod 100 = 0 Then
TextBox1.Show()
End If
TextBox1.AppendText(i.ToString)
Next
End Sub
///

I hope this helps?

Cor
 
H

Herfried K. Wagner [MVP]

John Smith said:
I have a form doing a large process. While this form is doing its
processing I want to write a status to a Textbox of where it is at in the
process. Similar to having a log file but within a textbox. As it
reaches
its mark it adds a line to the textbox "Step 2 is complete." or "Step 3
Failed because of...". My problem is that the text within the textbox
does
not display until after all of the processing is complete. How can I get
the text to display when it reaches each specific process?

Solution 1:

\\\
With Me.Label1
.Text = ...
.Refresh()
End With
Application.DoEvents() ' See documentation.
///

Solution 2:

Multithreading + Windows Forms:

<URL:http://msdn.microsoft.com/library/en-us/dnforms/html/winforms06112002.asp>
<URL:http://msdn.microsoft.com/library/en-us/dnforms/html/winforms08162002.asp>
<URL:http://msdn.microsoft.com/library/en-us/dnforms/html/winforms01232003.asp>

<URL:http://www.devx.com/dotnet/Article/11358/>

<URL:http://msdn.microsoft.com/library/e...SystemWindowsFormsControlClassInvokeTopic.asp>

Multithreading in Visual Basic .NET (Visual Basic Language Concepts)
<URL:http://msdn.microsoft.com/library/en-us/vbcn7/html/vaconthreadinginvisualbasic.asp>

Sample:

FileSystemEnumerator
<URL:http://dotnet.mvps.org/dotnet/samples/filesystem/downloads/FileSystemEnumerator.zip>
 
C

Chris, Master of All Things Insignificant

Herfried, maybe your example here can get you to answer a question I've
wondered about for a while.

With Me.Label1
.Text = ...
.Refresh()
End With

The idea behind the With clause is it allows for faster execution since the
"Me" ojbect doesn't have to be resolved 2 times in your example. But you
could rewrite your sample w/o the Me

With Label1
.Text = ...
.Refresh()
End With

In this case there wouldn't be any inhancement since you are not actually
eliminating the dot. Am I correct in my thinking?

Chris
 
H

Herfried K. Wagner [MVP]

Chris,

Chris said:
Herfried, maybe your example here can get you to answer a question I've
wondered about for a while.

With Me.Label1
.Text = ...
.Refresh()
End With

The idea behind the With clause is it allows for faster execution since
the "Me" ojbect doesn't have to be resolved 2 times in your example. But
you could rewrite your sample w/o the Me

With Label1
.Text = ...
.Refresh()
End With

In this case there wouldn't be any inhancement since you are not actually
eliminating the dot. Am I correct in my thinking?

The 'Me.' is resolved even if it's not explicitly written. In this case I
used With type the code faster ;-).
 
C

Cor Ligthert

Chis,

Not true,

The "Me" is only for the programmer, it does nothing at runtime.

The With clause creates an extra reference in a program. In this case it
will be slower than a program without a With clause, however think than
probably in parts of nanoseconds.

I hope this gives some ideas?

Cor


"Chris, Master of All Things Insignificant"
..
Herfried, maybe your example here can get you to answer a question I've
wondered about for a while.

With Me.Label1
.Text = ...
.Refresh()
End With

The idea behind the With clause is it allows for faster execution since
the "Me" ojbect doesn't have to be resolved 2 times in your example. But
you could rewrite your sample w/o the Me

With Label1
.Text = ...
.Refresh()
End With

In this case there wouldn't be any inhancement since you are not actually
eliminating the dot. Am I correct in my thinking?

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top