Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 201
  • Last Modified:

Reading an xml file and storing it to a list

Hey I'm trying to read an xml file and then store it to a list and then after that I want to get the information from the list and add it to the combo box on my form. I keep getting this error end of statement expected where the asterisks are. I'm just at a loss for how to get it from the list to the combo box.
Imports System.Xml
Public Class Form2
    Private Const Path As String = "procedures.xml"
    Dim settings As New XmlReaderSettings

    Private Const path2 As String = "NEW_CUST.xml"
    Dim settings2 As New XmlWriterSettings
    Dim xmlOut As XmlWriter = XmlWriter.Create(path2, settings2)

    Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBack.Click
        xmlOut.WriteEndElement()
        xmlOut.Close()
        Form1.Show()
        Me.Close()
    End Sub

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim Procedures As List(Of Procedure) = New List(Of Procedure)

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

        Dim xmlIn As XmlReader = XmlReader.Create(Path, settings)
        If xmlIn.ReadToDescendant("Procedure") Then

            Do
                Dim p As Procedure
                p.code = xmlIn("Code")
                xmlIn.ReadStartElement("Procedure")
                p.description = xmlIn.ReadElementContentAsString
                p.cost = xmlIn.ReadElementContentAsDecimal
                Procedures.Add(p)
            Loop While xmlIn.ReadToNextSibling("Procedure")
        End If

*****   For Each code In Procedure As Procedures
            cboCode.Items.Add(code)
        Next


        xmlIn.Close()
        settings2.Indent = True
        settings2.IndentChars = ("  ")

        xmlOut.WriteStartDocument()
        xmlOut.WriteStartElement("Patients")
    End Sub
    Private Sub txtPatient_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtPatient.Validating
        If Len(txtPatient.Text) < 4 Then
            MessageBox.Show("Patient number must be 4 digits!", "Entry Error")
            txtPatient.Select()
            e.Cancel = True
        End If
    End Sub

    Private Sub txtLast_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtLast.Validating
        If txtLast.Text = "" Then
            MessageBox.Show("You must enter a last name!", "Entry Error")
            txtLast.Select()
            e.Cancel = True
        End If
    End Sub

    Private Sub txtFirst_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtFirst.Validating
        If txtFirst.Text = "" Then
            MessageBox.Show("You must enter a first name!", "Entry Error")
            txtFirst.Select()
            e.Cancel = True
        End If
    End Sub

    Private Sub btnWrite_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWrite.Click
        Dim gender As String
        If rdoFemale.Checked = True Then
            gender = "Female"
        Else
            gender = "Male"
        End If
        xmlOut.WriteStartElement("Patients")
        xmlOut.WriteAttributeString("PatientNumber", txtPatient.Text)
        xmlOut.WriteAttributeString("LastName", txtLast.Text)
        xmlOut.WriteAttributeString("FirstName", txtFirst.Text)
        xmlOut.WriteAttributeString("Sex", gender)
        xmlOut.WriteAttributeString("Procedure", cboCode.Text)
        xmlOut.WriteAttributeString("Description", txtDescription.Text)
        xmlOut.WriteAttributeString("Cost", txtCost.Text)
    End Sub
End Class

Open in new window

0
theresa7584
Asked:
theresa7584
  • 2
  • 2
2 Solutions
 
EyalCommented:
0
 
theresa7584Author Commented:
Okay I found some information on it but I'm still getting this error:
Error      1      XML elements cannot be selected from type 'System.Collections.Generic.List(Of Reynolds_Assignment_3.Procedure)'.      

for this:
        For Each code In From element In ***Procedures.<Procedure>.***<Code>
            cboCode.Items.Add(code)
        Next
0
 
EyalCommented:
try
    For Each code In (From element In ***Procedures.<Procedure>.***<Code>).ToList<TYPE>()
            cboCode.Items.Add(code)
        Next
0
 
theresa7584Author Commented:
Thanks for the help!
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now