Question String array to a label

aroshlakshan

New member
Joined
Jan 11, 2011
Messages
4
Programming Experience
Beginner
I got a string array & i need to show the contents of it to a single label. it acts like a clock. the thing is i tried with everything i could but i failed. this is the code i've been trying. its in vb.net. and theres a thread running to slow down the loop so i can display the contents in a label for 2 seconds. is that the thing causing the problem?? please help. thanks...

Dim j As Integer
For j = 0 To readText.Length
label.text=readText(j)
Thread.Sleep(2000)
Next
 
You should always start with the documentation: Timer Class (System.Timers)

Here's a quick example using a timer:

VB.NET:
Public Class Form1

    Private tmr As Timer
    Private idx As Integer = 1
    Private arr As String() = {"1st", "2nd", "3rd", "4th", "5th"}

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        tmr = New Timer
        AddHandler tmr.Tick, AddressOf OnTick
        tmr.Interval = 2000
        tmr.Enabled = True
        Label1.Text = arr(0)
    End Sub

    Private Sub OnTick(ByVal source As Object, ByVal e As EventArgs)
        If idx = arr.Length Then
            idx = 0
        End If
        Label1.Text = arr(idx)
        idx += 1
    End Sub
End Class

I'd come back after you get the basics down to inquire about threading.
 
k heres the code. i still cant figure out whats going on. console application seems to work fine
okay heres the code. i still cant figure it out. please help me guys.

Imports System
Imports System.IO
Imports System.Threading




Public Class Form2
Dim readText() As String

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


Dim path As String = "c:\test.txt"
readText = File.ReadAllLines(path)

Dim temp As String
Dim i As Integer
Dim rnum As Integer
Dim r As New Random


For Each text As String In readText
rnum = r.Next(0, readText.Length)
temp = readText(i)
readText(i) = readText(rnum)
readText(rnum) = temp
Next text

Dim j As Integer
For j = 0 To readText.Length
Label1.Text = readText(j)
Thread.Sleep(2000)
Next j

End Sub

End Class
 
Back
Top