Hello.

Can someone tell me why this doesn't work?

Public Sub LoadFile()
        Dim file As StreamReader
        Dim temp As String
        Try
            file = New StreamReader("C:\file.txt)
            temp = file.ReadLine()
            While Not temp Is Nothing
                Dim ListaTemp() As String = temp.Split(CChar(","))
                ListBindingSource.Add(New Mod(CInt(ListTemp(0)), ListTemp(1), ListTemp(2)))
                temp = file.ReadLine()
            End While
            file.Close()
        Catch ex As Exception
            MsgBox("Not possible to read file.")
            Return
        End Try
    End Sub

Being that on the Mod class, I have 3 properties (string, double, double) and a list of something.

What I get always that I load this sub (even if the file exists) is the "Not possible to read file." message and it doesn't load to the form field. Since the saving to file function works, what it does is erase the content of the file.

Any thoughts?

Thank you in advance.

Recommended Answers

All 7 Replies

i assume you forgot the " in line 5 just here.
So if you change MsgBox("Not possible to read file.") to
MsgBox(ex.message) then it will tell you what is wrong.

commented: Helpful +1

Hello GeekByChoiCe. Thank you for your answer.

Yes, it was a mistake copying the code. If I replace the message box, I have the following message:

"Conversion from String test to type "Integer" is not valid.

Being that "test" is the first field on the text file.

How can I solve this?

You need to debug your app to test where the array's first index contains correct int ( digits) value or not.

Hello, adatapost.

Thank you for your answer.

I know it doesn't. The first field is a string and then 2 doubles. But how do can I add those to the form on that format?

>The first field is a string and then 2 doubles. But how do can I add those to the form on that format?

Can I see these values? Please attach "file.txt" here.

commented: Helpful +1

>The first field is a string and then 2 doubles. But how do can I add those to the form on that format?

Can I see these values? Please attach "file.txt" here.

It's ok, adatapost. I solved it by adding an Id field (integer) to the class.

Nonetheless, thank both of you for pointing me in the right way. :)

You're welcome! :)

I'm glad you got it working. Please mark this thread as solved if you have found an answer to your question and good luck!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.