CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2021

    Find And Change Attribute Value

    Hello everyone

    I'm fairly new to Visual Basic, so this question might be very "dumb" .
    For an assignment I have to read an XML (wines) into a listbox.
    From the listbox I then have to select an item and then I have to be able to change the data using. the data from the Textboxes (TBLand, TBName, TBType, TBStreek, TBDruif, TBAlcohol).
    Unfortunately this is not going well for me.

    I'm trying to search with a query where the information in the textboxes is not the same as the information in the listbox.
    If it is unique, I "select" it and then I want to change the value of the Name and Country to the value of the Textboxes and display it in the Listbox.

    When I run the program I get a "null" error.

    Do you know where I'm going wrong with this?

    Code of the Edit button:

    Private Sub ButtonEdit_Click(sender As Object, e As RoutedEventArgs) Handles ButtonWijzig.Click  
            ' De query voor elk attribuut uit het XML dat ongelijk is aan de waarde van de textbox  
            ' Dit element wordt veranderd in de waarde van de textbox  
            Dim query = From Wijn In xWijnen.Descendants("Wijn")  
                       Where TBLand.Text <> Wijn.Attribute("Land").Value _  
                        And TBNaam.Text <> Wijn.Attribute("Naam").Value _  
            And TBStreek.Text <> Wijn.Attribute("Streek").Value _  
            And TBSoort.Text <> Wijn.Attribute("Soort").Value _  
            And TBDruif.Text <> Wijn.Attribute("Druif").Value _  
            And TBAlcohol.Text <> Wijn.Attribute("AlcoholPrct").Value  
             Select WNaam = Wijn.Attribute("Naam").Value,  
                    WLand = Wijn.Attribute("Land").Value  
            For Each Wijn In query  
            Next Wijn

    Piece of code from the XML file:

    <Wijn Naam="Canapi Grillo" Land="Italie" Streek="Sicilie" Soort="Wit" Druif="Grillo" AlcoholPrct="12"/>  
    <Wijn Naam="Miopasso Fiano" Land="Italie" Streek="Sicilie" Soort="Wit" Druif="Fiano" AlcoholPrct="13"/>  

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004

    Re: Find And Change Attribute Value

    Set a breakpoint in your code and debug it. You be able to see variable values which will help you figure out what is going wrong.

  3. #3
    Join Date
    Jul 2001
    Sunny South Africa

    Re: Find And Change Attribute Value

    Select WNaam = Wijn.Attribute("Naam").Value,  
                    WLand = Wijn.Attribute("Land").Value
    Doesn't look right

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width