Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

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

What am I missing? simple RTB selection

I want this

John Doe
  Member: Yes
  HomePhone: None Available
  Cell Phone: 731-555-1234
  Address: 123 Some Street
  City: Milan
  State: TN
  Notes:  A simple description can go here or note

NOTE  the indent but what I am getting is what you see above on the first loop but as it lays in the rest of the contacts in the xml it indents them all like this

John Doe
  Member: Yes
  HomePhone: None Available
  Cell Phone: 731-555-1234
  Address: 123 Some Street
  City: Milan
  State: TN
  Notes:  A simple description can go here or note

  Jane Doe
  Member: Yes
  HomePhone: 731-234-6587
  Cell Phone: 731-555-1234
  Address: 765 Another Street
  City: Milan
  State: TN
  Notes:  A simple description can go here or note

NOTE Jane Doe should not be indented it should be like John Doe
Here is my code

Dim doc = XDocument.Load(myPath & "testXML.xml")



        For Each myCon In doc...<Contact>
            rtb1.SelectionStart = rtb1.TextLength
            Dim curFont As Font = rtb1.SelectionFont
            rtb1.SelectionFont = New Font(rtb1.Font, FontStyle.Bold)
            rtb1.AppendText(myCon.@Fname & " " & myCon.@Lname & vbNewLine) ' ////

            rtb1.SelectionFont = curFont
            rtb1.SelectionIndent = 8
            rtb1.AppendText("Member: " & myCon.@Member & vbNewLine)
            rtb1.AppendText("HomePhone: " & myCon.<HomePhone>.Value & vbNewLine)
            rtb1.AppendText("Cell Phone: " & myCon.<CellPhone>.Value & vbNewLine)
            rtb1.AppendText("Address: " & myCon.<Address>.Value & vbNewLine)
            rtb1.AppendText("City: " & myCon.<City>.Value & vbNewLine)
            rtb1.AppendText("State: " & myCon.<State>.Value & vbNewLine)
            rtb1.AppendText("Notes: " & myCon.<Notes>.Value & vbNewLine & vbNewLine)
        Next

Open in new window

0
vbMarkO
Asked:
vbMarkO
  • 2
1 Solution
 
vbMarkOAuthor Commented:
I was able to do it this way just playing around with it but it seems ... off

Is it right or better way of doing this
For Each myCon In doc...<Contact>
            rtb1.SelectionStart = rtb1.TextLength
            Dim curFont As Font = rtb1.SelectionFont
            rtb1.SelectionFont = New Font(rtb1.Font, FontStyle.Bold)
            rtb1.AppendText(myCon.@Fname & " " & myCon.@Lname & vbNewLine) ' ////

            rtb1.SelectionFont = curFont
            rtb1.SelectionIndent = 8
            rtb1.AppendText("Member: " & myCon.@Member & vbNewLine)
            rtb1.AppendText("HomePhone: " & myCon.<HomePhone>.Value & vbNewLine)
            rtb1.AppendText("Cell Phone: " & myCon.<CellPhone>.Value & vbNewLine)
            rtb1.AppendText("Address: " & myCon.<Address>.Value & vbNewLine)
            rtb1.AppendText("City: " & myCon.<City>.Value & vbNewLine)
            rtb1.AppendText("State: " & myCon.<State>.Value & vbNewLine)
            rtb1.AppendText("Notes: " & myCon.<Notes>.Value & vbNewLine & vbNewLine)
            rtb1.SelectionFont = curFont
            rtb1.SelectionIndent = 0
        Next

Open in new window

0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
I would refactor that like this:
Dim curFont As Font = rtb1.Font
        Dim boldFont As New Font(rtb1.Font, FontStyle.Bold)
        rtb1.SelectionStart = rtb1.TextLength
        For Each myCon In doc...<Contact>
            rtb1.SelectionFont = boldFont
            rtb1.SelectionIndent = 0
            rtb1.AppendText(myCon.@Fname & " " & myCon.@Lname & vbNewLine)

            rtb1.SelectionFont = curFont
            rtb1.SelectionIndent = 8
            rtb1.AppendText("Member: " & myCon.@Member & vbNewLine)
            rtb1.AppendText("HomePhone: " & myCon.<HomePhone>.Value & vbNewLine)
            rtb1.AppendText("Cell Phone: " & myCon.<CellPhone>.Value & vbNewLine)
            rtb1.AppendText("Address: " & myCon.<Address>.Value & vbNewLine)
            rtb1.AppendText("City: " & myCon.<City>.Value & vbNewLine)
            rtb1.AppendText("State: " & myCon.<State>.Value & vbNewLine)
            rtb1.AppendText("Notes: " & myCon.<Notes>.Value & vbNewLine & vbNewLine)
        Next
        boldFont.Dispose()

Open in new window

0
 
vbMarkOAuthor Commented:
Right on the money very understandable too

Thank you Idle_Mind you da man!!!
0

Featured Post

Industry Leaders: 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!

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