1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
   |  
'Corne & Tocsin :en VB.NET:index tableaux commencent à zero.
'un tableau de (137,3) elements est numerote de 0 à 136 et 0 à 2
'pour eviter des erreurs :
'utilise Length =>tableaux à une dimension
'utilise GetUpperBound(0),GetUpperBound(1)=>tableaux à une dimension
'
'Corne 2: utilise la declaration inline dans les boucles For.
'
'NB:plus grave encore il n'est pas posible en vb.net de declarer
'un tableau demarrant à 1
'
'Oyez,Oyez sujets de Messire VB.Net
'Qu'on se le dise.....
Option Explicit On
Imports System.IO
Public Class Form4
	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		ChargeTabPaysLang()
		'ChargeTabPaysLangBis()
	End Sub
	Public Sub ChargeTabPaysLang()
 
		Dim Words() As String
		' nettoie le code.A virer: Dim Word As String = String.Empty
		' deja declare inline dans la boucle for
 
		Dim TabPaysLang(137, 3) As String
		Dim FileString As String = String.Empty
		Dim strPath As String = My.Application.Info.DirectoryPath & "\_VAR_PAYS_PL.txt"
 
		If File.Exists(strPath) Then
			System.IO.File.WriteAllText(strPath, My.Resources._VAR_PAYS_PL)
		Else
			MessageBox.Show("Fichier des Pays -> Langues impossible à trouver..." & vbCrLf & "Désolé...")
			Exit Sub
		End If
 
		'Format de ligne  fichier : FRANCAIS_FRANCE*France.jpg*18
		Dim sReader As New System.IO.StreamReader(strPath)
 
		'Nettoyage :Dim I% reliquat ante-diluvien.
 
		'Declaration omise du X
		Dim X As Integer
 
		For I As Integer = 0 To TabPaysLang.Length - 1	  'utilise Length-1 :pas d'erreur sur les bornes de tableau
			FileString = sReader.ReadLine
			If FileString = "" Then Exit For
			Words = Split(FileString, "*")
 
			'X est un indice => part à zero et non 1  
			X = 0
			For Each Word As String In Words
 
				'Il ne beugle plus ou "warne" à cette ligne (au mot Word semble-t-il):
 
				If X = 0 Then TabPaysLang(I, X) = Word
				If X = 1 Then TabPaysLang(I, X) = Word
				If X = 2 Then TabPaysLang(I, X) = Word
				X = X + 1
			Next Word
		Next
		'Affiche les resultats dans TextBox1
		'utilise GetUpperBound pour  eviter
		'la aussi les erreurs sur les bornes des 2 dimensions
		For I As Integer = 0 To TabPaysLang.GetUpperBound(0)
			For J As Integer = 0 To TabPaysLang.GetUpperBound(1)
				Me.TextBox1.Text = Me.TextBox1.Text & TabPaysLang(I, J) & "  "
			Next
			'saut de ligne
			Me.TextBox1.Text = Me.TextBox1.Text & vbCrLf
		Next
 
	End Sub
	'version 2: corrigee plus simple et plus claire
	Public Sub ChargeTabPaysLangBis()
 
		Dim Words() As String
		Dim TabPaysLang(137, 3) As String
		Dim FileString As String = String.Empty
		Dim strPath As String = My.Application.Info.DirectoryPath & "\_VAR_PAYS_PL.txt"
 
		If File.Exists(strPath) Then
			System.IO.File.WriteAllText(strPath, My.Resources._VAR_PAYS_PL)
		Else
			MessageBox.Show("Fichier des Pays -> Langues impossible à trouver..." & vbCrLf & "Désolé...")
			Exit Sub
		End If
 
		'chaque ligne du fichier se présente comme suit : FRANCAIS_FRANCE*France.jpg*18
		Dim sReader As New System.IO.StreamReader(strPath)
 
		For I As Integer = 0 To TabPaysLang.Length - 1
			FileString = sReader.ReadLine
			If FileString = "" Then Exit For
			Words = Split(FileString, "*")
 
			'peut reecrit plus simplement encore
			For J As Integer = 0 To Words.Length - 1
				If J = 0 Then
					TabPaysLang(I, J) = Words(J)
				ElseIf J = 1 Then
					TabPaysLang(I, J) = Words(J)
				ElseIf J = 2 Then
					TabPaysLang(I, J) = Words(J)
				End If
			Next
		Next
		'Affiche les resultats dans textbox
		For I As Integer = 0 To TabPaysLang.GetUpperBound(0)
			For J As Integer = 0 To TabPaysLang.GetUpperBound(1)
				Me.TextBox1.Text = Me.TextBox1.Text & TabPaysLang(I, J) & "  "
			Next
			'saut de ligne
			Me.TextBox1.Text = Me.TextBox1.Text & vbCrLf
		Next
	End Sub
 
 
End Class | 
Partager