Ross Fuhrman
Ross Fuhrman

Reputation: 638

Easy way to remove warning messages after converting vb6 project to VB.NET

I have converted a VB6 project to VB.NET and am left with a large number of inline 'warning messages' such as "UPGRADE_WARNING: Couldn't resolve default property of object varJonSkeet" that I would like to get rid of. Is there a way to do this within Visual Studio 2008? Will it be easier to remove the warning messages with regex? I would prefer to do the removals one file at a time, but it isn't a dealbreaker.

Upvotes: 0

Views: 3292

Answers (5)

Brian Hoffman
Brian Hoffman

Reputation: 1

The VS 2008 method mentioned above does not work with VS 2010 and later. for VS 2010 and later follow these steps to remove upgrade warnings...

  1. CTRL + F
  2. Expand the "Find..." drop-down and select "Find In Files...".
  3. Select the "Replace in Files" tab.
  4. Find what: [^\S\r\n]'UPGRADE_WARNING:.*\r?\n
  5. Replace with: BLANK
  6. Expand "Find Options".
  7. Check "Use Regular Expressions".
  8. Begin your search/replace/replace all.

Explained: Using regex, the [^\S\r\n] tells regex to ignore the white-space at the beginning of the line, then obviously the 'UPGRADE_WARNING: is the start of the warning comment were looking for, then the .* tells regex to ignore everything else up to the *\r?\n, then the *\r?\n tells regex to also match the line-break at the end (without this part would leave a blank line where each warning would have been).

Upvotes: 0

Kristian Benning
Kristian Benning

Reputation: 91

Quick and simple fix if using VS 2008, use Find and Replace :

  • Open up the find options
  • Click 'use' and then select 'Wildcards'
  • In the 'Find what' put "'Upgrade Warning*" and leave the 'Replace with' blank
  • Click 'Replace All'

Upvotes: 5

Rob Kennedy
Rob Kennedy

Reputation: 163267

The best way to get rid of warnings is to address the suspicious code that the warnings complain about. That is, change the code such that it is no longer warning-worthy. Don't just seek to disable the generation of warnings altogether.

You'll need to provide more details about the specific warnings you're concerned about, and the accompanying code. But remember to search previous answers here first.


I see the warnings are actually text literally in your code, not messages issued in the compiler output. The way to get rid of those is to search for the keyword (UPGRADE_WARNING, I guess), consider whether the issue that it warns about has been addressed or is still a valid concern, fix the problem if there is one, and the delete that warning line. For example, does varJonSkeet have a default property, and if not, does it need one? Should you use to a non-default property instead? (You're not really asking how to delete a line of text, are you?)

If you've already gone through the whole file and determined that none of the warnings are valid, there's a quick way of removing all the warning lines.

grep -v UPGRADE_WARNING input_file.vb > output_file.vb
ren output_file.vb input_file.vb

If you don't already have grep on your system, then you don't have a complete development environment yet. Go get a copy. The -v option tells it to invert the search results, thus printing all lines that don't contain the search pattern. Those get written into the new file. Then replace the old file with the new one.

Upvotes: 2

Jeff Olson
Jeff Olson

Reputation: 329

I believe he is saying that he wants to remove the inline comments from his code.

Fastest way is to perform a find in files for UPGRADE_WARNING: and remove them by hand.

Or,

You could create a new .Net program to iterate through each .vb file in your source directory and read them in using a StreamReader and then write them out 1 line at a time to the same file and as you go omit any lines containing UPGRADE_WARNING:.

If you do the second way you will be that much better for having done some more vb.net coding.


   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim FileName As String = "c:\form1.vb"
        Dim SourceFile As System.IO.FileInfo = New FileInfo(FileName)
        Dim SourceTextStream As System.IO.TextReader = SourceFile.OpenText()

        Dim SourceFileContent() As String = Split(SourceTextStream.ReadToEnd(), vbCrLf)
        SourceTextStream.Close()

        Dim CurrentSourceLine As String
        Dim CurrentSourceLineNumber As Long

        Dim DestStream As StreamWriter = New StreamWriter(FileName)
        Dim LogStream As StreamWriter = New StreamWriter(FileName + ".log")

        For Each CurrentSourceLine In SourceFileContent
            CurrentSourceLineNumber += 1
            If InStr(CurrentSourceLine, "UPGRADE_WARNING") = 0 Then
                DestStream.WriteLine(CurrentSourceLine)
            Else
                ' Write to Log File
                LogStream.WriteLine("Line Skipped at number: " + CurrentSourceLineNumber.ToString())
            End If
        Next

        DestStream.Close()
        LogStream.Close()




    End Sub

Upvotes: 1

erikkallen
erikkallen

Reputation: 34391

Rewrite the project in VB.NET. Getting rid of the warnings might is only a means to get to the goal which (i presume) is a working program.

Upvotes: 0

Related Questions