?
Solved

XML True/False to Boolean and Back

Posted on 2006-05-28
2
Medium Priority
?
159 Views
Last Modified: 2010-05-18
In my application form I have a checkbox we will call cbxSub.
In my XML I have <sub>True</sub>  or it cam be <sub>False</sub>

Two part question:

If I need to read from the XML to the check box how will I do that? I know I could look at the string and say "If True then" or "If false then" but I am pretty sure there is another way.

Then if I have the checkbox and it is changed, how do I store the new value in the XML file?

Thanks
 
0
Comment
Question by:sneeri_c
2 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 2000 total points
ID: 16779279
Assuming you have your <sub> node in an IXMLDOMNode called "node", then you could try:

    If CBool(node.Text) Then
        cbxSub.Value = vbChecked
    End If
0
 
LVL 6

Expert Comment

by:junglerover77
ID: 16783515
Just put 2 command buttons and 1 checkbox on a form, and reference Microsoft XML v3.0, then try the following code:

Option Explicit
Dim oDoc As New MSXML2.DOMDocument30

Private Sub Command1_Click()
    Dim currNode As IXMLDOMNode
   
    oDoc.async = False
    Call oDoc.Load("c:\a.xml")
   
    For Each currNode In oDoc.childNodes
        Check1.Value = IIf(CBool(currNode.Text), vbChecked, vbUnchecked)
    Next
End Sub

Private Sub Command2_Click()
    Dim currNode As IXMLDOMNode
    Dim bol As Boolean

    For Each currNode In oDoc.childNodes
        bol = IIf(Check1.Value = vbChecked, True, False)
       
        currNode.Text = CStr(bol)
    Next
   
    Call oDoc.save("c:\a.xml")
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Set oDoc = Nothing
End Sub

The content of a.xml should be:
<sub>True</sub>
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question