|
-
Jul 28th, 2009, 04:12 PM
#1
Thread Starter
Lively Member
For Each...Next problem...
Here is my code. I have the Timer set at 2 seconds for now. It pulls the data in fine, sets the text for the label fine. But it only shows the last row of data and does not rotate through the rows.
Any ideas?
Code:
Public Class MarqueTest
Private Sub MarqueTest_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.AdminMessTableAdapter.Fill(Me.MarqueDataSet.AdminMess)
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim dr As DataRow
For Each dr In Me.MarqueDataSet.AdminMess.Rows
TitleLabel1.Text = dr.Item("DateSubmited") & " - " & dr.Item("Title") & " - POSTED BY " & dr.Item("CallSignSubmitted")
Next
End Sub
End Class
-
Jul 28th, 2009, 04:14 PM
#2
Re: For Each...Next problem...
try this:
Code:
For Each dr In Me.MarqueDataSet.AdminMess.Rows
TitleLabel1.Text += dr.Item("DateSubmited") & " - " & dr.Item("Title") & " - POSTED BY " & dr.Item("CallSignSubmitted").tostring & Environment.NewLine
Next
You keep clearing the textbox instead of adding text into it
Code:
TitleLabel1.Text = "Hello" ' Clear the textbox and add the string "Hello"
TitleLabel1.Text += " Hello" ' Adding the string "Hello" to the text that already stored inside the text box.
* Rate It  If you Like it
__________________________________________________________________________________________
" Programming is like sex: one mistake and you’re providing support for a lifetime."
Get last SQL insert ID 
-
Jul 28th, 2009, 04:44 PM
#3
-
Jul 28th, 2009, 04:45 PM
#4
Re: For Each...Next problem...
Why? What's wrong with += vs &= .... both have been overloaded for strings and produce the same result.
-tg
-
Jul 28th, 2009, 04:49 PM
#5
Re: For Each...Next problem...
I think mickey has a point it could raise an expectation if you mix strings with integers i believe don't it ?
* Rate It  If you Like it
__________________________________________________________________________________________
" Programming is like sex: one mistake and you’re providing support for a lifetime."
Get last SQL insert ID 
-
Jul 28th, 2009, 04:54 PM
#6
-
Jul 28th, 2009, 04:55 PM
#7
Re: For Each...Next problem...
you're right my friend but when you working with 3-5 languages at the same time it's hard to remember the correct syntax all the time, i'm working a lot with javascript at my work and += is the way to go in any situation
* Rate It  If you Like it
__________________________________________________________________________________________
" Programming is like sex: one mistake and you’re providing support for a lifetime."
Get last SQL insert ID 
-
Jul 28th, 2009, 04:59 PM
#8
Re: For Each...Next problem...
I was aiming for a little explanation to go with it... which is what I was trying elicit, and did get... on why using &= might be preferable over += .... to some of us, it's obvious, but to others it isn't so...
That is all. And now back to your regularly scheduled postings.
-tg
-
Jul 28th, 2009, 08:00 PM
#9
Thread Starter
Lively Member
Re: For Each...Next problem...
Thank you all for your quick replys, I will try the suggestions. I just wanted to make sure we are on the same page.
I am intending for the first row of data to show up and as the timer refreshes it moves to the next row of data until the end and starts over. Each time setting the text as described. Thus created alternating text like a new tickers, etc.
-
Jul 28th, 2009, 09:41 PM
#10
Re: For Each...Next problem...
Your problem is that EVERY time the Timer Ticks you loop through ALL the data and show EVERY row, one after the other. As such EVERY time the Timer Ticks you're going to show the first row, then replace it with the second, then replace it with the third, ... then replace it with the last. That's why you always see only the last record. All the others get replaced so quickly that you never see them.
What you should do is set an Integer variable to 0 and then, in the Tick event handler, you get the row at that index and then increment it by 1. That means that the first Tick will show the first row, the second Tick the second row, etc., etc. You'll obviously need to check whether you're at the last row each time and Stop the Timer if you are.
-
Jul 28th, 2009, 10:31 PM
#11
Thread Starter
Lively Member
Re: For Each...Next problem...
Thank you very much for that. I am understanding the process now but can you just give an example of how code for increasing by 1 would be.
I asume
dim start As Integer
start = 0
or something like that?
-
Jul 29th, 2009, 03:17 AM
#12
Re: For Each...Next problem...
That start var must be declared at the level of the class.
Something like this:
VB.NET Code:
Dim start As Integer = 0
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim dr As DataRow
If MarqueDataSet.Tables("AdminMess").Rows.Count > start Then
dr = MarqueDataSet.Tables("AdminMess").Rows(start)
TitleLabel1.Text = dr.Item("DateSubmited") & " - " & dr.Item("Title") & " - POSTED BY " & dr.Item("CallSignSubmitted")
start += 1
Else
Timer1.Stop()
End If
End Sub
Rate People That Helped You
Mark Thread Resolved When Resolved
-
Jul 29th, 2009, 07:33 AM
#13
Thread Starter
Lively Member
Re: For Each...Next problem...
-
Jul 29th, 2009, 10:35 AM
#14
Thread Starter
Lively Member
Re: For Each...Next problem...
Ok, next smal issue. I your code examle and it works like a champ BUT I cannot get it to do it continuiously. I have tried Do/Loop and other methods to no resolve.
-
Jul 29th, 2009, 10:43 AM
#15
Re: For Each...Next problem...
Do it continuously? What are you trying yo achieve?
If you want that code never stop instead of
put
Rate People That Helped You
Mark Thread Resolved When Resolved
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
|