0

I'm having the following problem, but can not identify the error, he points out that this is part of "Me.sr.Read (Me.srcBT, 0, CInt (Me.sr.Length))". Help.

Public Function getFile(ByVal srcFile As String) As String
    Dim result As String

    If File.Exists(srcFile) Then
        Using sr As FileStream = New FileStream(srcFile, FileMode.Open, FileAccess.ReadWrite, FileShare.None)
            Dim srcBT(CInt(sr.Length) + 1) As Byte
            Me.sr.Read(Me.srcBT, 0, CInt(Me.sr.Length))
            Me.sr.Flush()
            Me.sr.Dispose()
            Me.sr.Close()
            result = Encoding.[Default].GetString(Me.srcBT)
            Return result
        End Using
    End If
    result = Nothing

    Return result
End Function

enter image description here

Ňɏssa Pøngjǣrdenlarp
  • 38,411
  • 12
  • 59
  • 178
  • 2
    Get rid of all those `Me.`; if it compiles that way, it would be using some other `sr` and some other `srcCBT` objects. The ones you seem to need to use are all local. – Ňɏssa Pøngjǣrdenlarp Jul 20 '16 at 16:15
  • 1
    You can replace most of your code with `IO.File.ReadAllText (srcFile)` https://msdn.microsoft.com/en-us/library/ms143368(v=vs.110).aspx – Victor Zakharov Jul 20 '16 at 16:18
  • I have removed all "my", but the problem remains the same mistake. check to determine if the object is null before calling the method Additional information: Object reference not set to an instance of object – Marcelo Fior Jul 20 '16 at 16:20
  • `the problem remains the same mistake` which of course you havent yet told us what that is or whether it is a compiler error or exception. We dont live inside your computer – Ňɏssa Pøngjǣrdenlarp Jul 20 '16 at 16:21
  • Sorry, I'm a beginner, the error is as follows, as shown in the picture: http://imgur.com/a/7mi4p – Marcelo Fior Jul 20 '16 at 16:25

0 Answers0