Private Function GetListPoint() As List(Of PointF) Dim list1 As New List(Of String) Dim listp As New List(Of PointF) Dim val() As String Dim pt As PointF Try list1 = File.ReadAllLines("C:\test.txt").ToList For Each element As String In list1 val = element.Split(" "c) pt.X = Convert.ToSingle(val(0)) pt.Y = Convert.ToSingle(val(1)) listp.Add(pt) Next Catch ex As Exception MessageBox.Show(ex.ToString) End Try Return listp End Function
Dim p As New System.IO.StreamReader(My.Application.Info.DirectoryPath & "\fichier.txt") Do While p.Peek >= 0 ListBox1.Items.Add(Replace(p.ReadLine(), ".", ",")) Loop p.Close()
Dim v1 As Double = 0.0 Dim v2 As Double = 0.0 v1 = CDbl(Trim(Mid(ListBox1.Items(2), 1, 8))) v2 = CDbl(Trim(Mid(ListBox1.Items(2), 10)))
MsgBox(v1 & vbLf & v2)
pourquoi ne pas utiliser un objet, une liste invisible...
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionle PC de base c'est 8 Go de RAM
Oh, bientôt tout le monde sera en 64 bits,
Vers 1986 j'ai connu des entreprises qui avaient 11 ans de retard, tournant encore en 16 bits sous Windows 3.11
Imports System.IO Public Class Form1 Dim espace As String Dim Choixbouton As Integer Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load OpenFileDialog1.Filter = "Fichier DAT (*.dat)|*.dat|Fichiers texte (*.txt) |*.txt| Tous les fichiers(*.*)|*.*" End Sub Private Function GetListPoint() As List(Of PointF) Dim list1 As New List(Of String) Dim listp As New List(Of PointF) Dim val() As String Dim pt As PointF Try list1 = File.ReadAllLines(OpenFileDialog1.FileName).ToList Dim NbListe1 = list1.Count For I = 1 To NbListe1 - 2 val = list1(I).Split(CChar(vbTab)) val(0) = Replace(val(0), ".", ",") val(1) = Replace(val(1), ".", ",") Select Case Choixbouton Case Is = 1 ListBox1.Items.Add(val(0) & " " & val(1)) Case Is = 2 ListBox2.Items.Add(val(0) & " " & val(1)) Case Else MsgBox("erreur") End Select pt.X = Convert.ToSingle(val(0)) pt.Y = Convert.ToSingle(val(1)) listp.Add(pt) Next Catch ex As Exception MsgBox(ex.ToString) End Try Return listp End Function Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then Choixbouton = 1 ListBox1.Items.Clear() GetListPoint() End If End Sub Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then Choixbouton = 2 ListBox2.Items.Clear() GetListPoint() End If End Sub
Option Strict On Public Class Form1 Dim MaListView As New ListView With {.Parent = Me, _ .View = Windows.Forms.View.Details, _ .Bounds = Me.ClientRectangle} Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load MaListView.Columns.AddRange({New ColumnHeader() With {.Width 100, .Text "Point X"}, _ New ColumnHeader() With {.Width 100, .Text "Point Y"}}) Dim ofd As New OpenFileDialog() With {.Filter = "Fichiers Points|*.txt;*.dat", _ .InitialDirectory = Application.StartupPath} If ofd.ShowDialog = DialogResult.OK Then MaListView.Items.Clear() Using reader As New IO.StreamReader(ofd.FileName) Do While Not reader.EndOfStream Dim ligne() As String = reader.ReadLine.Split(" "c) Dim item As New ListViewItem(ligne(0)) item.SubItems.Add(ligne(1)) MaListView.Items.Add(item) Loop End Using End If End Sub End Class
Private Sub MesBoutons(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click, Button2.Click MessageBox.Show(DirectCast(sender, Button).Text) End Sub
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then MessageBox.show("Bonjour") Else Exit Function End If
Avertissement 1 La fonction 'GetListPoint' ne retourne pas une valeur pour tous les chemins de code. Une exception de référence null peut se produire au moment de l'exécution lorsque le résultat est utilisé. h:\mes documents\visual studio 2010\Projects\Créateur de Gcode1\Créateur de Gcode1\Form1.vb 30 29 Créateur de Gcode1
Option Strict On Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim lp As New List(Of PointF) From {New PointF(4.7, 3.6), New PointF(4.6, 4.5), New PointF(4.8, 2.1)} lp.Sort(AddressOf Tri) '... End Sub Private Function Tri(ByVal a As PointF, ByVal b As PointF) As Integer If a.X < b.X And a.Y < b.Y Then Return -1 'ici on peut déterminer d'autres valeurs de retour avec ElseIf Else return 1 End If End Function End Class