Change late binding after setting Option Strict on

Hugh Self Taught 81 Reputation points
2024-03-27T20:12:04.2066667+00:00

Hi Gurus, I am correcting errors after changing option strict to on. I have been able to correct everything with the exception of the following code which gets the outlook email signature file. The underline is under fso.getfile and under ts.readall

I can't seem to get CType correct so any guidance on this will be most appreciated.

'Dick Kusleika
Dim fso As Object, ts As Object = Nothing, tBoiler As String = Nothing, filesPath As String = Nothing
fso = CreateObject("Scripting.FileSystemObject")
ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
GetBoiler = ts.ReadAll

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,375 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,571 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,119 questions
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 26,506 Reputation points Microsoft Vendor
    2024-03-28T03:41:04.7333333+00:00

    Hi @Hugh Self Taught ,

    Consider using System.IO.StreamReader or System.IO.File to avoid late binding.

    Dim GetBoiler As String = Nothing
    
    'Using StreamReader
    Using reader As New StreamReader(filePath)
        tBoiler = reader.ReadToEnd()
    End Using
    
    'Using File.ReadAllText
    GetBoiler = File.ReadAllText(filePath)
    

    Best Regards.

    Jiachen Li


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful