I'm having a problem with loading a file into an array.
I have managed to load the contents into an arraylist.
what i'm trying to do is have a random number generated. the number would equal the position in an array, which holds the file name to a card. from that I want want to see if the array starts with a specific string ie: red, orange, etc...
I can do this with an array, but have not been able to do with with an arraylist and a text file.
Then I'm looking to go a bit further with having the card only being picked once. This would mean deleting it from the array, which I'm slowly figuring out and copying the contents back to the file. I know this in a bit inefficient right now. I'm trying to get it down first before cleaning the code up and pushing on further in more advance coding.
This here works fine right now. This is just used for when the form loads or when the new game button is pressed.
From here I can load the files into an arraylist but this is where i get stuck. Is there a way to have my rnd num be generated then pulled from the arraylist or would i have to copy my arraylist to a temp array and do this. I'm lost here.
Thanks in advance for any help.
I have managed to load the contents into an arraylist.
what i'm trying to do is have a random number generated. the number would equal the position in an array, which holds the file name to a card. from that I want want to see if the array starts with a specific string ie: red, orange, etc...
I can do this with an array, but have not been able to do with with an arraylist and a text file.
Then I'm looking to go a bit further with having the card only being picked once. This would mean deleting it from the array, which I'm slowly figuring out and copying the contents back to the file. I know this in a bit inefficient right now. I'm trying to get it down first before cleaning the code up and pushing on further in more advance coding.
This here works fine right now. This is just used for when the form loads or when the new game button is pressed.
Visual Basic:
Private Function initilaize()
Dim nowCards(14) As String, i As Integer
Dim myFile As String = "MainCards.dat"
If File.Exists(myFile) And myFile.Length > 0 Then
'do nothing
Else
Dim defCards As New StreamWriter(myFile, True)
'Cards currently being used
nowCards(0) = "red0.jpg"
nowCards(1) = "red1.jpg"
nowCards(2) = "red2.jpg"
nowCards(3) = "orange0.jpg"
nowCards(4) = "orange1.jpg"
nowCards(5) = "orange2.jpg"
nowCards(6) = "yellow0.jpg"
nowCards(7) = "yellow1.jpg"
nowCards(8) = "yellow2.jpg"
nowCards(9) = "white0.jpg"
nowCards(10) = "white1.jpg"
nowCards(11) = "white2.jpg"
nowCards(12) = "blue0.jpg"
nowCards(13) = "blue1.jpg"
nowCards(14) = "blue2.jpg"
For i = 0 To 14 'copy cards to file.
defCards.WriteLine(nowCards(i))
Next i
defCards.Close()
End If
end function
From here I can load the files into an arraylist but this is where i get stuck. Is there a way to have my rnd num be generated then pulled from the arraylist or would i have to copy my arraylist to a temp array and do this. I'm lost here.
Visual Basic:
'click event for drawing cards
Dim i As Short, r As Integer, fn, recCards() As String
Dim Cards As ArrayList = New ArrayList()
Dim myFile As String = "MainCards.dat"
Dim defCards As New StreamReader(myFile)
Dim ri As New Random()
defCards = File.OpenText(myFile)
While defCards.Peek <> -1
Cards.Add(defCards.ReadLine)
End While
Thanks in advance for any help.