Visual Basic .NET Forums  
Click here to advertise with us

Go Back   Visual Basic .NET Forums > VB.NET > VB.NET General Discussion

VB.NET General Discussion VB.NET general discussion area

VB.NET Forums Newsletter Signup:
Email address:


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-02-2008, 2:48 PM
VB.NET Forum Newbie
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Dec 2008
Posts: 3
Reputation: 0
hscorpio is on a distinguished programming path ahead
Default displaying info within a loop

Hi all

Can I please get some help on some basic coding.

The user Pushes a button on the form.
A 'For loop' begins at i=0
Textbox2 is set to display some information within the loop
Then it goes onto the next i. Again Textbox2 displays new information.

How do you go about doing this?

Many Thanks
Hscorpio
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 12-02-2008, 2:59 PM
JuggaloBrotha's Avatar
VB.NET Forum Moderator
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Jun 2004
Location: Lansing, MI; USA
Age: 25
Posts: 3,633
Reputation: 396
JuggaloBrotha master of VB.NETJuggaloBrotha master of VB.NETJuggaloBrotha master of VB.NETJuggaloBrotha master of VB.NETJuggaloBrotha master of VB.NETJuggaloBrotha master of VB.NETJuggaloBrotha master of VB.NETJuggaloBrotha master of VB.NETJuggaloBrotha master of VB.NET
Default

How hard is it to set the text property of a textbox from code? Me.Textbox1.Text = "Some text"

You can do that from within a loop too.
__________________
Currently using: VS 2005 & 2008 Pro w/sp1 on Win7 Ultimate x64.


There are 3 kinds of people in the world: Those who can count and those who can't.
4 out of 3 people have trouble with fractions.

Windows has a 64 bit GUI for a set of 32 bit extensions on a 16 bit shell for an 8 bit OS using a 4 bit kernel made by a 2 bit company that can't stand 1 bit of competition.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 12-02-2008, 3:56 PM
VB.NET Forum Newbie
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Dec 2008
Posts: 3
Reputation: 0
hscorpio is on a distinguished programming path ahead
Default

Not hard at all if you know the answer. I guess thats why I asked.

But you'll have to dumb it down a bit more for me.

for i = 0 to x
me.textbox2.text=textbox2.text & " " & aa(i)
next i

gives me the same result as I had before I added the me. windows form bit. It goes through the loop and the user only sees what comes out at the end.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 12-02-2008, 6:35 PM
VB.NET Forum Idol
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Feb 2008
Location: USA
Posts: 877
Reputation: 499
MattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond repute
Default

Code:
	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
	Handles MyBase.Load

		Me.BackgroundWorker1.WorkerReportsProgress = True
		Me.BackgroundWorker1.RunWorkerAsync()

	End Sub

	Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) _
	Handles BackgroundWorker1.DoWork

		For i As Integer = 0 To 10000
			BackgroundWorker1.ReportProgress(i / 100, i)
			Threading.Thread.Sleep(1)
		Next

	End Sub

	Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As System.Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) _
	Handles BackgroundWorker1.ProgressChanged

		Me.lblUserState.Text = "Number: " & e.UserState.ToString()
		Me.lblPercent.Text = e.ProgressPercentage.ToString() & "%"

	End Sub
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 12-02-2008, 9:58 PM
VB.NET Forum Genius
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Jun 2004
Posts: 226
Reputation: 105
Solitaire probably authored a book by nowSolitaire probably authored a book by now
Default

The following works for me:


Dim aa() As Integer = {2, 4, 6, 8, 10}
For i As Integer = 0 To 4
TextBox2.Text &= aa(i) & " "
Next
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 12-03-2008, 7:11 AM
cjard's Avatar
VB.NET Forum All-Mighty
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Apr 2006
Age: 65
Posts: 6,442
Reputation: 807
cjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond repute
Default

Quote:
Originally Posted by Solitaire View Post
The following works for me:
But, it doesnt work for the OP

He wants to count to.. say.. a million.. And he wants to see the numbers rolling up in the text box from 1 to a million (or the text extending each time). He does not want to click the Go button, and have the UI hang for 30 seconds while VB concatenates a million strings together and stores them in a text box and only reveals the result at the end, hence why MattP provided the BackgroundWorker example


hscorpio: note that MattP's example replaces the text each time. If you want to append the text each time, use textbox.AppendText("text") in place of textbox.Text = "text"

Note also that you DONT have to use e.ProgressPercentage (you can set it to 0 always, or use it to pass status codes) nor does it have to be a progress percentage at all; it can jump up and down and be totally unrelated to your operation's progress.
You can pass any information you like in the UserState parameter; MattP passes a number, i, but it can be a string, number, error, anything. At the other side, in the ProgressChanged event handler, convert the userstate back to what you want with DirectCast(e.UserState, <type>).
e.g. Suppose you had a custom class ReportState, you would

Code:
Dim myReportState as New ReportState
...
BackgroundWorker1.ReportProgress(i / 100, myReportState)

...
'and in the progress changed event handler:

...
Dim tmpRepState as ReportState = DirectCast(e.UserState, ReportState)
'now do whatever you want with the reportstate object
As an example, when using a background worker, i'll use the progress percentage as the level of logging from 0 to 5 (low to high) and the userstate as the message i want to log. You can also use the TypeOf() command to see what kind of object the UserState is, and perform different actions depending on what it is
__________________
DW1 DW2 DW3 DW4 DNU PQ

Last edited by cjard; 12-03-2008 at 7:16 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





All times are GMT -4. The time now is 9:37 AM.

Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2


For advertising opportunities click here.