conversion from string "System._ComObject" to type "double" not valid

conversion from string "System._ComObject" to type "double" not valid

Anonymous
Not applicable
1,154 Views
1 Reply
Message 1 of 2

conversion from string "System._ComObject" to type "double" not valid

Anonymous
Not applicable

Hello all,

I am trying to count the block references with the name "MISC4" in the modelspace drawing and then print the result on screen. I am using Cad11 (some computers here also run 2009) and VB 2010 Express.

 

I get a conversion error of 'conversion from String "System._ComObject" to type "double" not valid' ...

This problem is mainly a conversion issue to .net I believe but I can not figure out where or what variable is not being defined(or why).  New to the .net so I might not be utilizing the new features to the full potential.

 

Here is the code, with commented debug values (sorry it is very ugly in this code block and the ''' should be on the same line for comments)...

 

<code>

 Private Sub btnScan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnScan.Click
        Dim notes(100) As String
        Dim blkNote As Object
        Dim Scan As Integer
        Dim err1 As Integer
        Dim index As Integer
        Dim blks As AcadBlockReference
        Dim ent As AcadEntity
        Dim newNotes(200) As String
        

  For Each ent In ThisDrawing.ModelSpace 
    If ent.ObjectName.ToString = "AcDbBlockReference" Then
       blks = ent
       If blks.Name = "MISC4" Then
          Scan = 0
          err1 = 0
         Try
          blkNote = blks.GetAttributes ''blkNote={object()}
            Catch ex As Exception
             blkNote = ""
          End Try

          While Scan < 100
             If notes(Scan) = blkNote(0).ToString Then 
'''  notes(scan)=nothing so err1 = 0  
            err1 = 1
             End If
                Scan = Scan + 1
               'Net.disableAutoRelease(notes)  
'''locks (notes) value  '.disable' not a member of 'Net'
          End While
          If err1 = 0 Then
              notes(index) = blkNote(0).ToString 
'''notes(index) = "System._ComObject" 
'''notes(index) = "nothing" after Step Into
                 index = index + 1
       End If
      End If
     End If
     Next ent

      Scan = 0
      While Scan < 100
        If notes(Scan) > 100 Then '''breaks here  
'''conversion from string "System._ComObject" to type "double" not valid
          newNotes(Scan + 100) = notes(Scan)
        Else
          newNotes(notes(Scan)) = notes(Scan)
        End If
          Scan = Scan + 1
      End While

      Scan = 0
      While Scan < 200
        If newNotes(Scan) <> "" Then
           Try
              lbNotes.Items.Add(newNotes(Scan))
             Catch ex As Exception
           End Try
        End If
          Scan = Scan + 1
      End While
    End Sub

 </code>

 

 

Thank you for any help, it is greatly appreciated.

JS

0 Likes
1,155 Views
1 Reply
Reply (1)
Message 2 of 2

norman.yuan
Mentor
Mentor

It is not easy to understand what you really wanted to do with your code and what exactly you meant with your question.

 

If you just want to convert a string value "System._ComObject" to a number of Double type, then you simply cannot. No one knows "System._ComObject" literally implies 1 or 100, or whatever numerically.

 

If you meant to ask why notes(index) contains a string value "System._ComObject", not as you expected as a numeric value (be it a string, or a int/double...), then it is because your code does it in this line:

 

blkNote = blks.GetAttributes

...

 

and this line:

 

notes(Scan) = blkNote(0).ToString

 

let's see, blkNote is an array of AcadAttributeReference, returned by calling blks.GetAttributes(), of a COM type, not the value of the attribute that you may be expecting. Therefore blknote(0).ToString get you "System._ComObject", and your code assigned it to an element in the array "notes". In your later code, you try to convert it to a number, which of course will fail and break your code execution.

 

I suspect what you really want here is the Attribute value and place it into notes array, like this:

 

Dim arr As AcadAttributeReference

 

blkNote = blks.GetAttributes

...

arr=blkNote(0)

notes(Scan) = arr.TextString

 

You must notice that the attribute value is a String type, so is the notes(index).

 

So it may still fail at your code here:

 

If notes(Scan) > 100 Then...

 

You have to firstly make sure notes(Scan) actually contains a numeric string value, and then you need to convert it into a proper type to do your compare (int/double... with CInt() or CDbl() or Convert.ToInt32/Double...).

 

All of these have nothing to do with .NET itself and its new features, or with Acad versions

 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes