Question General Help...I think...

lostwages702

New member
Joined
Nov 1, 2010
Messages
3
Programming Experience
3-5
I have run into what I am thinking will be a simple solution, but I am just overlooking it. Below is a snippet from my program, which everything is working fine, it is just the syntax of this portion that I am having a slight issue with and I am hoping someone may be able to assist.

Here is a breakdown of the code below, if MyType.Type equals any of the types I have listed, then it will add a bold header (SectHedr), then it will add the lines with the type counts and other text. The only issue, is that it is adding the header before each line with the counts, but in reality, I need it to only add the header once, and then the lines with the counts like so:

General Features
Total lines found: 10
Total arcs found: 15

And this is what I am really getting:

General Features
Total lines found: 10
General Features
Total arcs found: 15
General Features
Total circles found: 1

VB.NET:
If MyType.Type.ToString.Equals("LINE") OrElse MyType.Type.ToString.Equals("ARC") OrElse _
   MyType.Type.ToString.Equals("CIRCLE") = True Then

    Dim SectHedr As String = "General Features"
    AppendBoldHdrTxt(RichTextBox1, SectHedr)
    RichTextBox1.AppendText(vbLf)

    If MyType.Type.ToString = "LINE" Then
        RichTextBox1.AppendText("Total lines found: " & AcObjCntr.ToString & vbLf)
    ElseIf MyType.Type.ToString = "ARC" Then
        RichTextBox1.AppendText("Total arcs found: " & AcObjCntr.ToString & vbLf)
    ElseIf MyType.Type.ToString = "CIRCLE" Then
        RichTextBox1.AppendText("Total circles found: " & AcObjCntr.ToString & vbLf)
    End If
End If

I hope this makes sense and that someone can give me an idea as to how to fix it give me the desired outcome. Thanks in advance.
 
It is in a For Each statement as shown below under a private sub which is called when i press a button or change a combobox selection... The MyObjTypes is an array of object types i have, this is being written for AutoCAD if it helps. I have shortened my list of object types as it does get quite long and I am only about 30% done with them :(.

VB.NET:
        Dim MyObjTypes As New List(Of MyObjType)()

        Dim TmpObj As New MyObjType()
        TmpObj.Type = "LINE"
        MyObjTypes.Add(TmpObj)
        'Other types exist here...

        For Each MyType As MyObjType In MyObjTypes

            If SelRes.Status = PromptStatus.OK Then

                Dim ObjSelSet As SelectionSet = AcSelRes.Value
                For Each SelObj As SelectedObject In ObjSelSet
                    If SelObj.ObjectId.ObjectClass.DxfName = MyType.Type Then
                        AcObjCntr = AcObjCntr + 1
                    Else
                    End If

                Next
                If AcObjCntr.ToString = "0" Then

                Else
                    If MyType.Type.ToString.Equals("LINE") OrElse MyType.Type.ToString.Equals("ARC") OrElse _
                       MyType.Type.ToString.Equals("CIRCLE") = True Then

                        Dim SectHedr As String = "General Features"
                        AppendBoldHdrTxt(RichTextBox1, SectHedr)
                        RichTextBox1.AppendText(vbLf)

                        If MyType.Type.ToString = "LINE" Then
                            RichTextBox1.AppendText("Total lines found: " & AcObjCntr.ToString & vbLf)
                        ElseIf MyType.Type.ToString = "ARC" Then
                            RichTextBox1.AppendText("Total arcs found: " & AcObjCntr.ToString & vbLf)
                        ElseIf MyType.Type.ToString = "CIRCLE" Then
                            RichTextBox1.AppendText("Total circles found: " & AcObjCntr.ToString & vbLf)
                        End If
                    End If
                    AcObjCntr = 0
                End If
            Else

            End If
        Next

You think I need to change it to a While loop or something like that?

Edit: Sorry bout that, I am using a piece of software a friend wrote that attempts to transfer code from VS Desktop to a browser form... I will have to let him know that it does not keep all formatting, but I have revised the code above.
 
Last edited:
You've made you code very hard to read because it lacks proper indenting. Please repost it with proper indenting so that it's easier to work out what is what. I could spend the time to work it out regardless but I shouldn't really have to when properly indented code would make it obvious.
 
Back
Top