XML True/False to Boolean and Back

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
 
sneeri_cAsked:
Who is Participating?
 
Carl TawnConnect With a Mentor Systems and Integration DeveloperCommented:
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
 
junglerover77Commented:
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
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.

All Courses

From novice to tech pro — start learning today.