8 Replies - 309 Views - Last Post: 29 November 2018 - 10:43 AM Rate Topic: -----

#1 winkimjr2   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 148
  • Joined: 30-May 12

How do I add a 3rd condition to my code vb.net code

Posted 28 November 2018 - 12:47 PM

In the xml document below, I would like to check for 3 things

1. If Phone/@Current ='true'
2. If Type/@Word ='HOME'
3. If Invalid is not true

I have done 1 and 2 but I am not sure how to do 3 in the same line of code.

My xml document which is put into an object objxmlPhoneNode

<?xml version="1.0" encoding="UTF-8"?>
<Phone Op="A" Current="true">
	<Type Op="A" Word="HOME">Home</Type>
	<Number Op="A">444-081-7031</Number>
	<Invalid>true</Invalid>
</Phone>




I have taken care of condition number 1 and 2. I need hep to add condition 3. i.e. If Invalid is not true.

objxmlPhoneNode = objXmlPartyNode.SelectSingleNode("Phone[@Current='true' and Type/@Word='HOME']")


Is This A Good Question/Topic? 0
  • +

Replies To: How do I add a 3rd condition to my code vb.net code

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14691
  • View blog
  • Posts: 58,718
  • Joined: 12-June 08

Re: How do I add a 3rd condition to my code vb.net code

Posted 28 November 2018 - 01:03 PM

How are you doing it with the first two parts?
Was This Post Helpful? 0
  • +
  • -

#3 winkimjr2   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 148
  • Joined: 30-May 12

Re: How do I add a 3rd condition to my code vb.net code

Posted 28 November 2018 - 01:07 PM

View Postmodi123_1, on 28 November 2018 - 01:03 PM, said:

How are you doing it with the first two parts?


I am using and for the 2 conditions. The reason I am not sure how to add the third condition is because Invalid element does not have an attribute.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14691
  • View blog
  • Posts: 58,718
  • Joined: 12-June 08

Re: How do I add a 3rd condition to my code vb.net code

Posted 28 November 2018 - 01:35 PM

You should really utilize the XMLNode object. It has that nice '.item' collection you can check with.
Was This Post Helpful? 0
  • +
  • -

#5 winkimjr2   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 148
  • Joined: 30-May 12

Re: How do I add a 3rd condition to my code vb.net code

Posted 28 November 2018 - 01:38 PM

View Postmodi123_1, on 28 November 2018 - 01:35 PM, said:

You should really utilize the XMLNode object. It has that nice '.item' collection you can check with.


I will have to study it and then try it.
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14691
  • View blog
  • Posts: 58,718
  • Joined: 12-June 08

Re: How do I add a 3rd condition to my code vb.net code

Posted 28 November 2018 - 01:41 PM

I gave an example in your previous topic.
Was This Post Helpful? 0
  • +
  • -

#7 IronRazer   User is offline

  • Custom Control Freak
  • member icon

Reputation: 1530
  • View blog
  • Posts: 3,856
  • Joined: 01-February 13

Re: How do I add a 3rd condition to my code vb.net code

Posted 28 November 2018 - 02:19 PM

Perhaps there is more that modi123_1 knows about what you are doing from past questions but, just figured I would throw in an answer to the question, just in case.

You can use another 'and' to test the condition of the Invalid node being 'true' or 'false'. It is basically no different than using the 'And' in your VB.net code, you can test several conditions in one (If..Then) statement.
objXmlPartyNode.SelectSingleNode("Phone[@Current='true' and Type/@Word='HOME' and Invalid='true']")

Was This Post Helpful? 1
  • +
  • -

#8 winkimjr2   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 148
  • Joined: 30-May 12

Re: How do I add a 3rd condition to my code vb.net code

Posted 29 November 2018 - 08:00 AM

View PostIronRazer, on 28 November 2018 - 02:19 PM, said:

Perhaps there is more that modi123_1 knows about what you are doing from past questions but, just figured I would throw in an answer to the question, just in case.

You can use another 'and' to test the condition of the Invalid node being 'true' or 'false'. It is basically no different than using the 'And' in your VB.net code, you can test several conditions in one (If..Then) statement.
objXmlPartyNode.SelectSingleNode("Phone[@Current='true' and Type/@Word='HOME' and Invalid='true']")


Thanks so much. Based on your suggestion I did it this way. I had to use not(Invalid='true') because I only care when it is not true.
/Phone[@Current='true' and Type/@Word='HOME' and not(Invalid='true')]

This post has been edited by winkimjr2: 29 November 2018 - 08:04 AM

Was This Post Helpful? 0
  • +
  • -

#9 dbasnett   User is offline

  • D.I.C Addict
  • member icon

Reputation: 121
  • View blog
  • Posts: 671
  • Joined: 01-October 08

Re: How do I add a 3rd condition to my code vb.net code

Posted 29 November 2018 - 10:43 AM

Because this is VB I'd use XElement

        Dim objxmlPhoneNode As XElement
        'to load from file or URI
        ' objxmlPhoneNode = XElement.Load("URI or Path Here")

        'for testing
        objxmlPhoneNode = <Phone Op="A" Current="true">
                              <Type Op="A" Word="HOME">Home</Type>
                              <Number Op="A">444-081-7031</Number>
                              <Invalid>true</Invalid>
                          </Phone>

        Dim current As Boolean = Boolean.Parse([email protected])
        Dim invalid As Boolean = Boolean.Parse(objxmlPhoneNode.<Invalid>.Value)
        Dim word As String = objxmlPhoneNode.<Type>[email protected]



One of the things that is useful is literals. The code above is not complete.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1