0

For a school project we need to make a BoardGame, Now I have made a list of location for the NPC.

These locations are stored in a txt file named player2.txt, as followed http://pastebin.com/ZhbSvjSt

Im using the following the code to read them from the file. http://pastebin.com/UjLSeWrQ

Dim TurnP2 As String = IO.File.ReadAllLines(".\player2.txt")(Turn)
Dim source As String = TurnP2
Dim result() As String = Split(source, ",")

But now I'm stuck, I have no clue how to splits these 3 numbers into variable. For example Take the first row 1,1,5

I need it to place these numbers in the following variables:

CoX = 1
CoY = 1
CoZ = 5

Can anyone help me further?

Also sorry for using pastebin, but I got a strange error while trying to post.

Regards Jurre

1
  • I am sure your teacher would like you to figure this out on your own, not to have a bunch of professionals write your code for you. Commented Oct 17, 2013 at 15:11

2 Answers 2

1

I would create a Class:

   Private Class Coords
        Public coordX As Integer
        Public coordY As Integer
        Public coordz As Integer
    End Class

And then I would fill a list:

    Dim source As String() = System.IO.File.ReadAllLines(".\player2.txt")
    Dim ListCoords = New List(Of Coords)

    For Each Val As String In source

        Dim s As String() = Val.Split(",")

        ListCoords.Add(New Coords With {.coordX = s(0).ToString, _
                             .coordY = s(1).ToString, _
                             .coordz = s(2).ToString})

    Next

You will have a list of loaded coordinates:

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

As an offtopic, maybe could you say the name/url of the VS IDE color theme that are you using, maybe you are using a 3rd party extension?, or just you've modified one of the default dark themes adding your desired colours?
0

You have multiple lines, so are CoX,CoY,CoZ arrays?

You can use a loop to initialize them. Presuming always valid data:

Dim TurnP2 As String() = IO.File.ReadAllLines(".\player2.txt")
Dim CosX(TurnP2.Length - 1) As Int32
Dim CosY(TurnP2.Length - 1) As Int32
Dim CosZ(TurnP2.Length - 1) As Int32
For i As Int32 = 0 To TurnP2.Length - 1
    Dim values = TurnP2(i).Split(","c)
    CosX(i) = Int32.Parse(values(0))
    CosY(i) = Int32.Parse(values(1))
    CosZ(i) = Int32.Parse(values(2))
Next

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.