VB Application only reads every other field in XML file.

Hello, see the attached files. I aim to move XML data into a multiline textbox on form1 from the xml file. Everything works exactly as it should, except for the fact that the textbox only receives every other value. The code for this operation begins on line 208 of form1.vb, sub procedure btnSaveXMLData_Click. Thanks in advance for the help! SimpleCalculator.exe XMLforSimpleCalc
'Name           Simple Caculator
'Purpose        To create calculation and save them in a 10 object array
'Programer      Robert Kraft on 3/13/2011

Option Strict On
Option Explicit On
Option Infer Off

Imports System.Data.SqlClient
Imports System.Xml



Public Class frmCalc

    Private mathoperation As MathOperations
    Private Const path As String = "C:\Users\Robert\Desktop\AMU\ENTD461\Week7\XMLforSimpleCalc"
    Dim resultsList As New List(Of String)(10)
    Dim dblFirstNum As Double
    Dim dblSecondNum As Double
    Dim dblResult As Double
    Dim strOperation As String
    Dim strResults As String
    Dim newQuid As String

   

    Private Sub radAddition_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radAddition.CheckedChanged
        txtOperation.Text = "+"
        strOperation = txtOperation.Text
    End Sub

    Private Sub radSubtraction_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radSubtraction.CheckedChanged
        txtOperation.Text = "-"
        strOperation = txtOperation.Text
    End Sub

    Private Sub radMultiplication_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radMultiplication.CheckedChanged
        txtOperation.Text = "*"
        strOperation = txtOperation.Text
    End Sub

    Private Sub radDivision_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radDivision.CheckedChanged
        txtOperation.Text = "/"
        strOperation = txtOperation.Text
    End Sub

    Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
        Double.TryParse(txtFirstNumber.Text, dblFirstNum)
        Double.TryParse(txtSecondNumber.Text, dblSecondNum)

        If radAddition.Checked Then
            mathoperation = New Addition(CDbl(txtFirstNumber.Text), CDbl(txtSecondNumber.Text), txtOperation.Text)
        ElseIf radSubtraction.Checked Then
            mathoperation = New Subtraction(CDbl(txtFirstNumber.Text), CDbl(txtSecondNumber.Text), txtOperation.Text)
        ElseIf radMultiplication.Checked Then
            mathoperation = New Multiplication(CDbl(txtFirstNumber.Text), CDbl(txtSecondNumber.Text), txtOperation.Text)
        ElseIf radDivision.Checked Then
            If dblSecondNum <> 0 Then
                mathoperation = New Division(CDbl(txtFirstNumber.Text), CDbl(txtSecondNumber.Text), txtOperation.Text)
            Else : dblSecondNum = 0
                MessageBox.Show("Cannot Divide by Zero", _
                                "Zero Division", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                txtSecondNumber.Focus()
                txtSecondNumber.SelectAll()
                txtResult.Text = "Nothing"
            End If
        End If

        If txtResult.Text = "Nothing" Then
            txtResult.Text = ""
        Else
            txtResult.Text = mathoperation.GetFinalValue
        End If
       
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click

        resultsList.Add(txtResult.Text)

        txtFinalResults.Text = Nothing
        txtFirstNumber.Text = Nothing
        txtSecondNumber.Text = Nothing
        txtResult.Text = Nothing
        txtFirstNumber.Focus()

    End Sub

    Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
        Dim final As String = ""
        For Each d As String In resultsList
            final &= d & vbCrLf
        Next
        txtFinalResults.Text = final

       
    End Sub

    Private Sub frmCalc_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'TODO: This line of code loads data into the 'DataForSimpleCalculatorDataSet.Updated' table. You can move, or remove it, as needed.
        Me.UpdatedTableAdapter.Fill(Me.DataForSimpleCalculatorDataSet.Updated)
        'TODO: This line of code loads data into the 'DataForSimpleCalculatorDataSet.Equations' table. You can move, or remove it, as needed.
        Me.EquationsTableAdapter.Fill(Me.DataForSimpleCalculatorDataSet.Equations)
        radAddition.Checked = True

        txtFinalResults.Text = Nothing
        txtFirstNumber.Text = Nothing
        txtSecondNumber.Text = Nothing
        txtResult.Text = Nothing
        txtQuid.Text = Nothing
        txtFirstNumber.Focus()
        mtxtDate.Text = CStr(Date.Now)
    End Sub

    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        txtFinalResults.Text = ""
        resultsList.Clear()
    End Sub

    Private Sub txtFirstNumber_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtFirstNumber.KeyPress, txtSecondNumber.KeyPress
        If (e.KeyChar < "0" OrElse e.KeyChar > "9") _
            AndAlso e.KeyChar <> ControlChars.Back _
            AndAlso e.KeyChar <> "-" Then
            e.Handled = True
        End If
    End Sub

   

  
    Private Sub btnSaveToDatabase_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveToDatabase.Click


        Try

            Dim equationrow As DataForSimpleCalculatorDataSet.EquationsRow
            equationrow = Me.DataForSimpleCalculatorDataSet.Equations.NewEquationsRow
            equationrow.Equations = txtFinalResults.Text
            equationrow.ID = CInt(CInt(txtQuid.Text) & vbCrLf)
            Me.DataForSimpleCalculatorDataSet.Equations.AddEquationsRow(equationrow)
            EquationsTableAdapter.Update(Me.DataForSimpleCalculatorDataSet.Equations)


            Dim dateRow As DataForSimpleCalculatorDataSet.UpdatedRow
            dateRow = Me.DataForSimpleCalculatorDataSet.Updated.NewUpdatedRow
            dateRow.WhenUpdated = CDate(mtxtDate.Text)
            dateRow.ID = CInt(txtQuid.Text)
            Me.DataForSimpleCalculatorDataSet.Updated.AddUpdatedRow(dateRow)
            UpdatedTableAdapter.Update(Me.DataForSimpleCalculatorDataSet.Updated)
        Catch ex As SqlException
            MessageBox.Show("SQL Server error # " & ex.Number & ": " & ex.Message, ex.GetType.ToString)
        Catch ex As Exception
            MessageBox.Show("The Key entered already exists in the database. Please coose another key", "Key Error")


        End Try

        txtFinalResults.Text = Nothing
        txtFirstNumber.Text = Nothing
        txtSecondNumber.Text = Nothing
        txtResult.Text = Nothing
        txtQuid.Text = Nothing
        resultsList.Clear()
        txtFirstNumber.Focus()

    End Sub

   
    Private Sub txtQuid_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtQuid.KeyPress
        If (e.KeyChar < "0" OrElse e.KeyChar > "9") _
           AndAlso e.KeyChar <> ControlChars.Back _
           Then
            e.Handled = True
        End If
    End Sub

    Private Sub btnModify_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnModify.Click
        Dim F2 As New Form2
        F2.show()

    End Sub


    Private Sub btnSaveXMLData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveXMLData.Click
        Dim settings As New XmlWriterSettings
        settings.Indent = True
        settings.IndentChars = ("    ")

        Dim xmlOut As XmlWriter = XmlWriter.Create(path, settings)

        xmlOut.WriteStartDocument()
        xmlOut.WriteStartElement("EquationsList")

        xmlOut.WriteElementString("ID", txtQuid.Text)

        For i As Integer = 0 To resultsList.Count - 1
           
            xmlOut.WriteElementString("Equations", resultsList(i))
        Next

        xmlOut.WriteElementString("WhenUpdated", mtxtDate.Text)

        xmlOut.WriteEndElement()
        xmlOut.Close()
    End Sub

    Private Sub btnOpenXML_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenXML.Click

        Dim settings As New XmlReaderSettings
        settings.IgnoreComments = True
        settings.IgnoreWhitespace = True

        Dim xmlin As XmlReader = XmlReader.Create(path, settings)

        If xmlin.ReadToDescendant("EquationsList") Then

            xmlin.ReadStartElement("EquationsList")
            txtQuid.Text = xmlin.ReadElementContentAsString

            Do
                Dim i As String = xmlin.ReadElementContentAsString

                resultsList.Add(i)
                
            Loop While xmlin.ReadToNextSibling("Equations")

            Dim final As String = ""
            For Each d As String In resultsList
                final &= d & vbCrLf
            Next
            txtFinalResults.Text = final

        End If
        xmlin.Close()
    End Sub
End Class

Open in new window

LVL 2
psychokraftAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
Try the modification below.

The reason you see this behavior is because your ReadElementAsString() calls are advancing to the the next node as well. Since the next node is an Equations node, when you call ReadToNextSibling(), you are effectively skipping that "current" Equation.
Dim settings As New XmlReaderSettings
settings.IgnoreComments = True
settings.IgnoreWhitespace = True

Dim xmlin As XmlReader = XmlReader.Create(path, settings)

If xmlin.ReadToDescendant("EquationsList") Then

    xmlin.ReadStartElement("EquationsList")
    txtQuid.Text = xmlin.ReadElementContentAsString

    Do
        Dim i As String = xmlin.ReadElementContentAsString

        resultsList.Add(i)

        If xmlin.Name <> "Equations" Then
            xmlin.ReadToNextSibling("Equations")
        End If
    Loop While Not xmlin.EOF AndAlso xmlin.Name = "Equations"

    Dim final As String = ""
    For Each d As String In resultsList
        final &= d & vbCrLf
    Next
    txtFinalResults.Text = final

End If

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.