Van txt naar textbox en terug

Status
Niet open voor verdere reacties.

Schipperjte

Gebruiker
Lid geworden
24 jan 2006
Berichten
212
Hoi,

Heb wat gevonden wat je textboxen naar een txt file schrijft en ook weer terug met een button.Heb er in totaal een stuk of 30 maar dat maakt niet uit.



maar krijg foutmelding
Error 1 'ElementAt' is not a member of 'System.Array'.

Code:
Dim FileLocation As String = My.Application.Info.DirectoryPath & "\twain.DLL"
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        For Each Control In Me.Controls
            If TypeOf (Control) Is TextBox Then My.Computer.FileSystem.WriteAllText(FileLocation, Control.name & "," & Control.text & vbCrLf, True)
        Next


    End Sub

    Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If My.Computer.FileSystem.FileExists(FileLocation) Then
            Dim fileContents As String = My.Computer.FileSystem.ReadAllText(FileLocation)
            Dim SplitUpData() As String = fileContents.Split(vbCrLf)

            For Each entry As String In SplitUpData
                For Each Control In Me.Controls
                    If TypeOf (Control) Is TextBox Then
                        If Control.name = (entry.Split(",").ElementAt(0).Trim) Then
                            Control.text = (entry.Split(",").ElementAt(1).Trim)
                        End If
                    End If
                Next
            Next

        End If
    End Sub


Ik gebruik VB 2010


Bas
 
Vervang de code onder Form5_Load met deze code:

Code:
        If My.Computer.FileSystem.FileExists(FileLocation) Then
            Dim fileContents As New StreamReader(FileLocation)

            While fileContents.Peek <> -1
                Dim Line As String = fileContents.ReadLine
                Dim SplitUpData() As String = Line.Split(",")
                For Each Control In Me.Controls
                    If TypeOf Control Is TextBox Then
                        If Control.Name = SplitUpData(0) Then
                            Control.Text = SplitUpData(1)
                        End If
                    End If
                Next
            End While
        End If

Waarom geef je je tekstbestandje de extensie dll? Een dll is normaal gesproken geen tekstbestand... Doe dan iets als .cfg, .ini, .dat of whatever. Of laat het gewoon txt.
 
Laatst bewerkt:
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan