Je viens d'adapter le code de alex, sous forme d'une fonction voici le code :
Je voudrais savoir comment appeler la fonction dans un sub, qui se situe dans un autre document,' je vous remercie pour vos futurs réponses.
Public Function trajet() As Integer
Dim objStreamReader As StreamReader
Dim strLine As String
'Pass the file path and the file name to the StreamReader constructor.
objStreamReader = New StreamReader("data/trajert.txt")
'Read the first line of text.
strLine = objStreamReader.ReadLine
'Continue to read until you reach the end of the file.
Do While Not strLine Is Nothing
'Do something here
'Read the next line.
strLine = objStreamReader.ReadLine
Loop
'Close the file.
objStreamReader.Close()
Console.ReadLine()
Dim PathSteps As New Dictionary(Of String, String)
Do While Not strLine Is Nothing
'Do something here
Dim parts() As String = strLine.Split(" ")
Dim coords As String = parts(0)
Dim direction As String = parts(1)
PathSteps.Add(coords, direction)
If direction = "Haut" Then
SeDeplacerMap(changeurHaut)
End If
If direction = "Bas" Then
SeDeplacerMap(changeurBas)
End If
If direction = "Gauche" Then
SeDeplacerMap(changeurGauche)
End If
If direction = "Droite" Then
SeDeplacerMap(changeurDroite)
End If
'Read the next line.
strLine = objStreamReader.ReadLine
Loop
End Function
Dim objStreamReader As StreamReader
Dim strLine As String
'Pass the file path and the file name to the StreamReader constructor.
objStreamReader = New StreamReader("data/trajert.txt")
'Read the first line of text.
strLine = objStreamReader.ReadLine
'Continue to read until you reach the end of the file.
Do While Not strLine Is Nothing
'Do something here
'Read the next line.
strLine = objStreamReader.ReadLine
Loop
'Close the file.
objStreamReader.Close()
Console.ReadLine()
Dim PathSteps As New Dictionary(Of String, String)
Do While Not strLine Is Nothing
'Do something here
Dim parts() As String = strLine.Split(" ")
Dim coords As String = parts(0)
Dim direction As String = parts(1)
PathSteps.Add(coords, direction)
If direction = "Haut" Then
SeDeplacerMap(changeurHaut)
End If
If direction = "Bas" Then
SeDeplacerMap(changeurBas)
End If
If direction = "Gauche" Then
SeDeplacerMap(changeurGauche)
End If
If direction = "Droite" Then
SeDeplacerMap(changeurDroite)
End If
'Read the next line.
strLine = objStreamReader.ReadLine
Loop
End Function
Je voudrais savoir comment appeler la fonction dans un sub, qui se situe dans un autre document,' je vous remercie pour vos futurs réponses.