Question I need to pull out just the numbers from a txt doc

inkedgfx

Well-known member
Joined
Sep 29, 2012
Messages
139
Location
USA
Programming Experience
Beginner
I have a lottery program I am working on... its almost complete but need one more thing done to it....

I have it saving the winning numbers drawn from the lottery... it saves to a txt doc then if the user clicks view numbers, a listbox is filled with the saved txt doc...the txt doc has numbers and letters in it..I would like to fill the listbox with just the numbers, so I then can generate a randome set of numbers from the numbers pulled from the txt doc...if that makes any sence at all.....also the numbers(5) will be an unknown array , I put 5 just so I could test it out....as the txt doc grows , so will the numbers array...not sure how to code that part either.......

here is what I have -
this is in a button click event
Dim path As String = Application.StartupPath & "\lotteryNumbers\WinningNumbers.txt"
Dim ListtoSplit As String = path
Dim Index, numbers(5) As Integer
Dim stringSplit() As String = ListtoSplit.Split(",")
Dim i As Integer
Do While (ListNumbers.SelectedItems.Count > 0) ' clear the listbox before putting the numbers in
ListNumbers.Items.Clear()
Loop

For i = 0 To stringSplit.Length - 1 'find the numbers in the ListtoSplit variable
If stringSplit(i).Contains(",") Then
If Integer.TryParse(stringSplit(i + 1), numbers(Index)) Then
Index += 1
ListNumbers.Items.Add(numbers(0)) ' add each number to the listbox
If Index = 6 Then Exit For
End If
End If

Next

thank you for any help.

InkedGFX
 
ok,,ok....maybe I asked to many questions or whatever.... but I have the solution....after many hours of coding and testing , coding again, testing again...you get the picture.....

here is my solution

Dim Path As String = Application.StartupPath & "\LotteryNumbers\WinningNumbers.txt"
Dim stream_reader As New StreamReader(Path)
Dim line As String
Dim numbers() As String = Nothing
line = stream_reader.ReadToEnd()
numbers = line.Split(",")
Dim n As String
Do Until (ListNumbers.SelectedItems.Count = 0) ' clear the listbox before putting the numbers in
ListNumbers.Items.Clear()
Loop
For Each n In numbers ' pull each number out of the text file
If IsNumeric(n) = True Then
ListNumbers.Items.Add(n) ' load the listbox with the numbers
End If
Next n

InkedGFX
 
Back
Top