Jorr3
Jorr3

Reputation: 29

How to open text file and parse it

I have the following question. On my form I write away my form with the value "76,50" as "07650". Now I want to open my file again in the listbox with the value 76,50 instead of 07650.

Public Class AddwhenOpen 

Public number As Integer
Public name As String
Public Birthday As Integer
Public perc As Decimal
Public comboboxvalue As String

Public Function ToStringForPrinter() As Decimal

Return comboboxvalue & nummer.ToString.PadLeft(5) & naam.PadLeft(5) & Geboortejaar.ToString.PadRight(5) & (perc / 100).ToInt64("00,00")

End Function

Code for CLASS

`Public Class ChangeFormatBackToDecimal

Public number As Integer
Public name As String
Public Bday As Integer
Public perc As Decimal
Public comboboxvalue As String

Public Function TostringForPrinter() As String
    Return comboboxvalue & number.ToString.PadLeft(5) & name.PadLeft(5) & Bday.ToString.PadRight(5) & Format(perc / 100, "#00,00")
End Function`

Code when opening the file...

    Dim index As Integer = 0
    Dim lijn As String

    'Keuzelijst leegmaken.
    lstOutput.Items.Clear()


    With dlgOpenen
        .Filter = "textfiles (*.txt) | *.txt"
        .FileName = ""
        .InitialDirectory = "C:\My Documents"
        .Title = "Open"
    End With

    If dlgOpenen.ShowDialog = DialogResult.OK Then
        FileOpen(1, dlgOpen.FileName, OpenMode.Input)
        Do While Not EOF(1)
            line = LineInput(1)
            lstOutput.Items.Add(line)
        Loop
        FileClose(1)
    End If
    Resetdefaultvalue()

Dim data As New ChangeFormatBackToDecimal

    data.comboboxvalue = cboAfdeling.SelectedItem.ToString.PadRight(5) & cboKlasGetal.SelectedItem.ToString & cboAfdeling.SelectedItem.ToString & cboKlasLetter.SelectedItem.ToString.PadRight(5)

    data.number = CInt(txtNumber.Text)
    data.name = txtName.Text
    data.Bday = CInt(txtBday.Text)
    data.perc = CDec(txtPerc.Text)


    lstOutput.Items.Add(data)

Can someone help me?

Upvotes: 0

Views: 257

Answers (1)

matzone
matzone

Reputation: 5719

To change string 76,50 instead of 07650.

Dim n as Integer = val("07650")

Dim s as String = format(s/100)

This is optional ...

s = s.Replace(".",",") 
s = s.PadRight(5,"0")  

ABOUT YOUR CODE :

It should be

Return comboboxvalue & nummer.ToString.PadLeft(5) & naam.PadLeft(5) & Geboortejaar.ToString.PadRight(5) & format(perc / 100,"#0.00")

Upvotes: 2

Related Questions