Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Option Strict On disallows implicit conversions from
Message
From
26/10/2015 18:01:29
 
 
To
All
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Option Strict On disallows implicit conversions from
Environment versions
Environment:
VB 9.0
OS:
Windows 8.1
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01626470
Message ID:
01626470
Views:
34
Hello everyone;

I have this sub:
    Public Sub FindFileAndReplaceTextIn(ByVal sourceDir As String, ByVal filenameFind As String,
                                        ByVal txtfind As String, ByVal txtreplace As String,
                                        ByVal comparisonType As StringComparison)
        For Each topDir As DirectoryInfo In New DirectoryInfo(sourceDir).GetDirectories("*", SearchOption.TopDirectoryOnly)
            For Each txtfile As FileInfo In topDir.GetFiles("*.txt", SearchOption.TopDirectoryOnly)
                If txtfile.Name.Equals(filenameFind, StringComparison.OrdinalIgnoreCase) Then
                    Dim txt As String = File.ReadAllText(txtfile.FullName, Encoding.Default).
                                             Replace(txtfile.FullName, txtfind, txtreplace, comparisonType)
                    File.WriteAllText(txtfile.FullName, txt, Encoding.Default)
                End If
            Next txtfile
        Next topDir
    End Sub
I use this sub in this case:
            Dim comparisonType As StringComparison = StringComparison.OrdinalIgnoreCase
            FindFileAndReplaceTextIn(sourceDir, "GL.txt", "MCBO-02", "MBO-03", comparisonType)
            FindFileAndReplaceTextIn(sourceDir, "GL.txt", "MCBO-03", "MBO-03", comparisonType)
            FindFileAndReplaceTextIn(sourceDir, "IMP6000.txt", "TXT01", "MBO-03", comparisonType)
            FindFileAndReplaceTextIn(sourceDir, "IMP6000.txt", "TXT02", "MBO-03", comparisonType)
I´m having trouble with the parameter called txtreplace (fourth parameter) due to the VS give me back this message: Option Strict On disallows implicit conversions from String to StringComparison.

I have changed the parameter definition with txtreplace As StringComparison instead of txtreplace As String, but once I did it; I get the error when I call the funtion and the VS suggest me change this
FindFileAndReplaceTextIn(sourceDir, "GL.txt", "MCBO-02", "MBO-03", comparisonType)
for
FindFileAndReplaceTextIn(sourceDir, "GL.txt", "MCBO-02", CType("MBO-03", StringComparison), comparisonType)
Does anyone the idea how can I fix this issue?

Thanks in advance.
Next
Reply
Map
View

Click here to load this message in the networking platform