Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionImports System.IO Public Class Form1 Private Structure datarecord Public count As Integer Public chaine As String End Structure Private tableout As New List(Of datarecord) Private table As New List(Of String) Private Sub ReadFile() Dim pathfichier As String pathfichier = "E:\test.TXT" 'je lis tout le fichier dans listitems Try table = System.IO.File.ReadAllLines(pathfichier).ToList Catch ex As Exception 'en cas d'exception affiche l'erreur MessageBox.Show(ex.Message) End Try End Sub Private Sub WriteFile() Dim pathfichier As String pathfichier = "E:\testout.TXT" Dim outfile As New StreamWriter(pathfichier) 'j'écris le fichier Try For Each element In tableout outfile.WriteLine(String.Concat(element.count, " ", element.chaine)) Next outfile.Close() Catch ex As Exception 'en cas d'exception affiche l'erreur MessageBox.Show(ex.Message) End Try End Sub Private Sub Process() Dim count As Integer Dim str As String Dim datarec As datarecord count = 0 table.Sort() str = table(0) For Each element In table If element = str Then count += 1 Else datarec.chaine = str datarec.count = count tableout.Add(datarec) count = 0 str = element End If Next datarec.chaine = str datarec.count = count tableout.Add(datarec) End Sub Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ReadFile() Process() WriteFile() End Sub End Class
'plus facile de mettre tes données dans un listbox
Imports System.IO Public Class Form1 Private Structure datarecord Public count As Integer Public chaine As String End Structure Private tableout As New List(Of datarecord) Private table As New List(Of String) Private Sub ReadListbox() table.Clear() For Each item In ListBox1.Items table.Add(item) Next End Sub Private Sub WriteTolistbox() For Each item In tableout ListBox2.Items.Add(String.Concat(item.count, " )", item.chaine)) Next End Sub Private Sub Process() Dim count As Integer Dim str As String Dim datarec As datarecord count = 0 table.Sort() str = table(0) For Each element In table If element = str Then count += 1 Else datarec.chaine = str datarec.count = count tableout.Add(datarec) count = 0 str = element End If Next datarec.chaine = str datarec.count = count tableout.Add(datarec) End Sub Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ReadListbox() Process() WriteTolistbox() End Sub End Class
Imports System.IO
Private Structure datarecord Public count As Integer Public chaine As String End Structure
Public Class Form1
Private tableout As New Generic.List(Of datarecord) ' List(Of datarecord) Private table As New Generic.List(Of String) 'List(Of String)
Public Class frmOpti Inherits System.Windows.Forms.Form Private Structure datarecord Public count As Integer Public chaine As String End Structure Private Sub Calculate() If bLoaded = False Then Exit Sub '****** recuperation de la longueur de barres - les chutes****** BinPackingGraph2.BinHeight = CType(nudBinHeight.Value - CInt(cmbchute.Text) - CInt(cmbchute.Text), Integer) '********************* ***************************** BinPackingGraph2.Decreasing = cbDecreasing.Checked BinPackingGraph2.Algorithm = CType(cbBinPackingAlgorithm.SelectedIndex, Bin_Packing_Graph.BinPackingGraph.BinPackingAlgorithm) Dim strElements() As String = txtElements.Text.Split(" "c) Dim intElements(strElements.GetUpperBound(0)) As Integer Dim bSuccess As Boolean = True Dim i As Integer For i = 0 To strElements.GetUpperBound(0) If IsNumeric(strElements(i)) Then intElements(i) = CType(strElements(i), Integer) Else bSuccess = False End If Next If bSuccess Then BinPackingGraph2.Elements = intElements BinPackingGraph2.Compute() End If ' ****** somme des barres ****** Dim somme As String somme = Bin_Packing_Graph.BinPackingGraph.Nbrs txtNbrsBarres.Text = somme '****** içi on rempli le txt ****** Me.txtLigne.Text = "" Dim enligne()() As Integer Dim k, j As Integer enligne = Bin_Packing_Graph.BinPackingGraph.liste For k = 0 To enligne.Length - 1 For j = 0 To enligne(k).Length - 1 If chkEpaisseur.Checked = False Then txtLigne.Text = txtLigne.Text & enligne(k)(j) & " " Else txtLigne.Text = txtLigne.Text & enligne(k)(j) - 8 & " " End If Next txtLigne.Text = txtLigne.Text & Environment.NewLine Next ' içi on rempli le listBox avec le contenu du textBox Dim Tab1() As String Dim x As Integer Me.ListBox1.Items.Clear() Tab1 = Split(txtLigne.Text, vbCrLf) For x = 0 To UBound(Tab1) ListBox1.Items.Add(Tab1(x)) Next ReadListbox() Process() WriteTolistbox() Private tableout As New Generic.List(Of datarecord) ' List(Of datarecord) Private table As New Generic.List(Of String) 'List(Of String) Private Sub ReadListbox() table.Clear() For Each item In ListBox1.Items table.Add(item) Next End Sub Private Sub WriteTolistbox() For Each item In tableout ListBox2.Items.Add(String.Concat(item.count, " )", item.chaine)) Next End Sub Private Sub Process() Dim count As Integer Dim str As String Dim datarec As datarecord count = 0 table.Sort() str = table(0) For Each element In table If element Is str Then count += 1 Else datarec.chaine = str datarec.count = count tableout.Add(datarec) count = 0 str = element End If Next datarec.chaine = str datarec.count = count tableout.Add(datarec) End Sub End Class
End Structure Private Sub Calculate()
Private tableout As New Generic.List(Of datarecord) ' List(Of datarecord) Private table As New Generic.List(Of String)
Private Structure datarecord Public count As Integer Public chaine As String End Structure Private tableout As New List(Of datarecord) Private table As New List(Of String)
Public Class frmOpti Inherits System.Windows.Forms.Form Private Structure datarecord Public count As Integer Public chaine As String End Structure Private tableout As New Generic.List(Of datarecord) Private table As New Generic.List(Of String) Private bLoaded As Boolean = False Private Sub Calculate() If bLoaded = False Then Exit Sub '****** recuperation de la longueur de barres - les chutes****** BinPackingGraph2.BinHeight = CType(nudBinHeight.Value - CInt(cmbchute.Text) - CInt(cmbchute.Text), Integer) '********************* ***************************** BinPackingGraph2.Decreasing = cbDecreasing.Checked BinPackingGraph2.Algorithm = CType(cbBinPackingAlgorithm.SelectedIndex, Bin_Packing_Graph.BinPackingGraph.BinPackingAlgorithm) Dim strElements() As String = txtElements.Text.Split(" "c) Dim intElements(strElements.GetUpperBound(0)) As Integer Dim bSuccess As Boolean = True Dim i As Integer For i = 0 To strElements.GetUpperBound(0) If IsNumeric(strElements(i)) Then intElements(i) = CType(strElements(i), Integer) Else bSuccess = False End If Next If bSuccess Then BinPackingGraph2.Elements = intElements BinPackingGraph2.Compute() End If ' ****** somme des barres ****** Dim somme As String somme = Bin_Packing_Graph.BinPackingGraph.Nbrs txtNbrsBarres.Text = somme '****** içi on rempli le txt ****** Me.txtLigne.Text = "" Dim enligne()() As Integer Dim k, j As Integer enligne = Bin_Packing_Graph.BinPackingGraph.liste For k = 0 To enligne.Length - 1 For j = 0 To enligne(k).Length - 1 If chkEpaisseur.Checked = False Then txtLigne.Text = txtLigne.Text & enligne(k)(j) & " " Else txtLigne.Text = txtLigne.Text & enligne(k)(j) - 8 & " " End If Next txtLigne.Text = txtLigne.Text & Environment.NewLine Next ' içi on rempli le listBox avec le contenu du textBox Dim Tab1() As String Dim x As Integer Me.ListBox1.Items.Clear() Tab1 = Split(txtLigne.Text, vbCrLf) For x = 0 To UBound(Tab1) ListBox1.Items.Add(Tab1(x)) Next ' içi on rempli le listBox2 avec le contenu du ListBox1 ReadListbox() Process() WriteTolistbox() End Sub Private Sub ReadListbox() Dim item As String '''Rajout de ma part table.Clear() For Each item In ListBox1.Items table.Add(item) Next End Sub Private Sub WriteTolistbox() Dim item As datarecord '''Rajout de ma part For Each item In tableout ListBox2.Items.Add(String.Concat(item.count, " )", item.chaine)) Next End Sub Private Sub Process() Dim count As Integer Dim str As String Dim datarec As datarecord Dim element As String '''Rajout de ma part count = 0 table.Sort() str = table(0) For Each element In table If element Is str Then count += 1 Else datarec.chaine = str datarec.count = count tableout.Add(datarec) count = 0 str = element End If Next datarec.chaine = str datarec.count = count tableout.Add(datarec) End Sub