How to display multiple messages in one MsgBox()? [VB.NET]

936 Views Asked by At

I would like to scan my xml file whether the specific node is exists or not. Then, I wanted to show the number of files in a message box. For example, when I browse multiply files, then the output will show difference results in the MsgBox()

This is what I have tried:

 Private Sub WritingFile(ByVal strContent As String)
 Dim xmlDoc As New XmlDocument()
        xmlDoc.Load(strContent)

        Dim nodes As XmlNode

        Try
            nodes = xmlDoc.DocumentElement.SelectSingleNode("\PRODUCT\NAME")
                If nodes Is Nothing Then
                MsgBox("File Not Exist")<----<--- should display the no. of files not exists
            Else
                MsgBox("File Exists") <--- should display the no. of files exists
            End If

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
End Sub

How can I display the results without the messagesbox display one by one for each files? Thank you

1

There are 1 best solutions below

0
Andrew Mortimer On

This is an example of how you could loop through the list of xml files

Private fileWithNode As Integer
Private fileWithoutNode As Integer

Private Sub CountValidFiles()

    Dim xmlFilePath As String = "c:\temp\myxmlfiles\"
    fileWithNode = 0
    fileWithoutNode = 0

    For Each filePath As String In Directory.GetFiles(xmlFilePath)
        ValidateFile(filePath)
    Next

    MessageBox.Show(String.Concat(String.Format("Files without node: {0}", fileWithoutNode),
                                  Environment.NewLine,
                                  String.Format("Files with node: {0}", fileWithNode)))

End Sub

Private Sub ValidateFile(strContent As String)
    Dim xmlDoc As New XmlDocument()
    xmlDoc.Load(strContent)

    Dim nodes As XmlNode

    Try
        nodes = xmlDoc.DocumentElement.SelectSingleNode("\PRODUCT\NAME")
        If nodes Is Nothing Then
            fileWithoutNode += 1 ' the no. Of files Not exists
        Else
            fileWithNode += 1 ' the no. Of files exists
        End If

    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try
End Sub