Resolved Split() String code not working

inkedgfx

Well-known member
Joined
Sep 29, 2012
Messages
139
Location
USA
Programming Experience
Beginner
Hello ,

I wrote a sub to get a txt file from a web site then it supposed to split the numbers in the txt file and fill labels with the numbers....everything works except it doesnt fill the last label with a number....wondering why?

code:

 Dim SourceNumbers As String = GetLotterynumbers()
        Dim num As String = Mid(SourceNumbers, 1)
        Dim DrawDate As Match = Regex.Match(SourceNumbers, "[0-9]*/[0-9]*/[0-9]{4}")
        WinningNumbersDrawDate = DrawDate.Value
        Dim stringSplit() As String = num.Split(","c)
        Dim Index, numbers(5) As Integer
        lblWinningNumbers.Text = lblWinningNumbers.Text & " " & WinningNumbersDrawDate
        For i As Integer = 0 To stringSplit.Length - 1
            If Integer.TryParse(stringSplit(i + 1), numbers(Index)) Then
                Index += 1

                Label1.Text = numbers(0)
                Label2.Text = numbers(1)
                Label3.Text = numbers(2)
                Label4.Text = numbers(3)
                Label5.Text = numbers(4)
                Label6.Text = numbers(5)
                WinningNumberOne = numbers(0)
                WinningNumberTwo = numbers(1)
                WinningNumberThree = numbers(2)
                WinningNumberFour = numbers(3)
                WinningNumberFive = numbers(4)
                WinningNumberSix = numbers(5)
                If Index = 6 Then Exit For
            End If
        Next


thanks for any help.

InkedGFX
 
Last edited:
Your loop doesn't make sense. What EXACTLY does 'num' contain? Why is GetlotteryNumbers returning a String instead of a String()? Is there any chance that GetLotteryNumbers will return an invalid result?
 
I got my code to work ......I also commented it out a little so I can tell whats going on.

       Dim SourceNumbers As String = GetLotterynumbers() ' this is the text doc on the website with the winning lottery numbers
        Dim num As String = Mid(SourceNumbers, 12) ' this is the line with the numbers
        Dim DrawDate As Match = Regex.Match(SourceNumbers, "[0-9]*/[0-9]*/[0-9]{4}") ' this is the date of the latest drawing
        WinningNumbersDrawDate = DrawDate.Value
        Dim stringSplit() As String = num.Split(","c) ' this splits the numbers by the "," i.e 1,2,3,4,5,6 = 1 2 3 4 5 6

        lblWinningNumbers.Text = lblWinningNumbers.Text & " " & WinningNumbersDrawDate
       

        Label1.Text = stringSplit(0)
        Label2.Text = stringSplit(1)
        Label3.Text = stringSplit(2)
        Label4.Text = stringSplit(3)
        Label5.Text = stringSplit(4)
        Label6.Text = stringSplit(5)


InkedGFX
 
Back
Top