What's wrong with this code

What's wrong with this code

Anonymous
Not applicable
525 Views
9 Replies
Message 1 of 10

What's wrong with this code

Anonymous
Not applicable
Hello,

I'm trying to nest a xref in a block. The code I wrote adds a line first, it
inserts a xref in the drawing but it does not nest it in the block. What do
I do wrong?

Thanks in advance,
Jan Appelman
LENGKEEK architecten en ingenieurs

Public Sub Nest_ExternalReference()

Dim InsertPoint(0 To 2) As Double
Dim PathName As String

' Define external reference to be inserted
InsertPoint(0) = 1: InsertPoint(1) = 1: InsertPoint(2) = 0
PathName = "p:\project\wijnreno\wrlogo.dwg"

' add block with nema "strStempel" to blockscollection
Dim objBlk As AcadBlock
Set objBlk = ThisDrawing.Blocks.Add(InsertPoint, "strStempel")

' add line to block
Dim entline As AcadLine
Dim stp(0 To 2) As Double
Dim eip(0 To 2) As Double
stp(0) = 0: stp(1) = 0: stp(2) = 0
eip(0) = 5: eip(1) = 5: eip(2) = 0
Set entline = objBlk.AddLine(stp, eip)

' add xref to block
Dim xrefLogo As AcadExternalReference
Set xrefLogo = objBlk.AttachExternalReference(PathName, "logo",
InsertPoint, 1#, 1#, 1#, 0, True)

' insert block
Dim blockRef As AcadBlockReference
Set blockRef = ThisDrawing.ModelSpace.InsertBlock(InsertPoint,
"strStempel", 1#, 1#, 1#, 0)

' Zoom all
ThisDrawing.Application.ZoomAll

End Sub
0 Likes
526 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable
I don't think it's possible to create a block definition with an
external reference as a member.

--
http://www.acadx.com
"You keep using that word. I do not think it means what you think it
means."

"Jan Appelman" wrote in message
news:824C0090298E5E385D39D7A062F53B61@in.WebX.SaUCah8kaAW...
> Hello,
>
> I'm trying to nest a xref in a block. The code I wrote adds a line
first, it
> inserts a xref in the drawing but it does not nest it in the block.
What do
> I do wrong?
0 Likes
Message 3 of 10

Anonymous
Not applicable
This is a little sub that I use for calculating mass of circular objects.
----------------------------------------------------------------------------
---
Public Sub Circle()

Dim d As Double
Dim h As Double

On Error GoTo ErrorControl
d = txtDiameter.Text
h = txtHeight.Text
txtMass.Text = (((pi * d * d / 4) * h) / 1000000000)
Exit Sub

ErrorControl:
If txtDiameter.Text = "" Then
MsgBox "Enter Diameter!", vbOKOnly, "Error Control"
txtDiameter.SetFocus
ElseIf txtHeight.Text = "" Then
MsgBox "Enter Height!", vbOKOnly, "Error Control"
txtHeight.SetFocus
End If
End Sub
----------------------------------------------------------------------------
---
I believe that it works OK if I enter values for Diameter and Height larger
then "8" (I'm nott 100% sure I didn't try all the numbers). But if the
number is smaller then "8" it doesn't return the correct value. It's much
bigger then it should be.

What is wrong here? Should I declare "d" and "h" as something else then
Double.

Thanks, Marko.
0 Likes
Message 4 of 10

Anonymous
Not applicable
What are you using for the value of Pi?

Pi = Atn(1) * 4

Joe

Marko Rogic wrote in message
news:C9242FE8D3165510EB5201C4F4FF63F4@in.WebX.maYIadrTaRb...
> This is a little sub that I use for calculating mass of circular objects.
> --------------------------------------------------------------------------
--
> ---
> Public Sub Circle()
>
> Dim d As Double
> Dim h As Double
>
> On Error GoTo ErrorControl
> d = txtDiameter.Text
> h = txtHeight.Text
> txtMass.Text = (((pi * d * d / 4) * h) / 1000000000)
> Exit Sub
>
> ErrorControl:
> If txtDiameter.Text = "" Then
> MsgBox "Enter Diameter!", vbOKOnly, "Error Control"
> txtDiameter.SetFocus
> ElseIf txtHeight.Text = "" Then
> MsgBox "Enter Height!", vbOKOnly, "Error Control"
> txtHeight.SetFocus
> End If
> End Sub
> --------------------------------------------------------------------------
--
> ---
> I believe that it works OK if I enter values for Diameter and Height
larger
> then "8" (I'm nott 100% sure I didn't try all the numbers). But if the
> number is smaller then "8" it doesn't return the correct value. It's much
> bigger then it should be.
>
> What is wrong here? Should I declare "d" and "h" as something else then
> Double.
>
> Thanks, Marko.
>
>
>
0 Likes
Message 5 of 10

Anonymous
Not applicable
I've declared it like this:

Public Const pi As Double = 3.141592654



"Joe Sutphin" wrote in message
news:63C5392CB589E89933D452EADF049567@in.WebX.maYIadrTaRb...
> What are you using for the value of Pi?
>
> Pi = Atn(1) * 4
>
> Joe
>
> Marko Rogic wrote in message
> news:C9242FE8D3165510EB5201C4F4FF63F4@in.WebX.maYIadrTaRb...
> > This is a little sub that I use for calculating mass of circular
objects.
>
> --------------------------------------------------------------------------
> --
> > ---
> > Public Sub Circle()
> >
> > Dim d As Double
> > Dim h As Double
> >
> > On Error GoTo ErrorControl
> > d = txtDiameter.Text
> > h = txtHeight.Text
> > txtMass.Text = (((pi * d * d / 4) * h) / 1000000000)
> > Exit Sub
> >
> > ErrorControl:
> > If txtDiameter.Text = "" Then
> > MsgBox "Enter Diameter!", vbOKOnly, "Error Control"
> > txtDiameter.SetFocus
> > ElseIf txtHeight.Text = "" Then
> > MsgBox "Enter Height!", vbOKOnly, "Error Control"
> > txtHeight.SetFocus
> > End If
> > End Sub
>
> --------------------------------------------------------------------------
> --
> > ---
> > I believe that it works OK if I enter values for Diameter and Height
> larger
> > then "8" (I'm nott 100% sure I didn't try all the numbers). But if the
> > number is smaller then "8" it doesn't return the correct value. It's
much
> > bigger then it should be.
> >
> > What is wrong here? Should I declare "d" and "h" as something else then
> > Double.
> >
> > Thanks, Marko.
> >
> >
> >
>
>
0 Likes
Message 6 of 10

Anonymous
Not applicable
Then I would change that declaration to this

pi = Atn(1) * 4

Joe

Marko Rogic wrote in message
news:103C1B846966B4E9CC0378696ADC8028@in.WebX.maYIadrTaRb...
> I've declared it like this:
>
> Public Const pi As Double = 3.141592654
>
>
>
> "Joe Sutphin" wrote in message
> news:63C5392CB589E89933D452EADF049567@in.WebX.maYIadrTaRb...
> > What are you using for the value of Pi?
> >
> > Pi = Atn(1) * 4
> >
> > Joe
> >
> > Marko Rogic wrote in message
> > news:C9242FE8D3165510EB5201C4F4FF63F4@in.WebX.maYIadrTaRb...
> > > This is a little sub that I use for calculating mass of circular
> objects.
> >
>
> --------------------------------------------------------------------------
> > --
> > > ---
> > > Public Sub Circle()
> > >
> > > Dim d As Double
> > > Dim h As Double
> > >
> > > On Error GoTo ErrorControl
> > > d = txtDiameter.Text
> > > h = txtHeight.Text
> > > txtMass.Text = (((pi * d * d / 4) * h) / 1000000000)
> > > Exit Sub
> > >
> > > ErrorControl:
> > > If txtDiameter.Text = "" Then
> > > MsgBox "Enter Diameter!", vbOKOnly, "Error Control"
> > > txtDiameter.SetFocus
> > > ElseIf txtHeight.Text = "" Then
> > > MsgBox "Enter Height!", vbOKOnly, "Error Control"
> > > txtHeight.SetFocus
> > > End If
> > > End Sub
> >
>
> --------------------------------------------------------------------------
> > --
> > > ---
> > > I believe that it works OK if I enter values for Diameter and Height
> > larger
> > > then "8" (I'm nott 100% sure I didn't try all the numbers). But if the
> > > number is smaller then "8" it doesn't return the correct value. It's
> much
> > > bigger then it should be.
> > >
> > > What is wrong here? Should I declare "d" and "h" as something else
then
> > > Double.
> > >
> > > Thanks, Marko.
> > >
> > >
> > >
> >
> >
>
>
0 Likes
Message 7 of 10

Anonymous
Not applicable
Thanks for the tip I'll try it tommorow at work.
0 Likes
Message 8 of 10

Anonymous
Not applicable
Arghhhh, how stupid can I be. The program worked just fine all along. But
because my text box for result wasn't big enough, I didn't see the very end
of result where the "E-04" or whatever was situated.
Which brings me to another question, how do you control the precision.



"Joe Sutphin" wrote in message
news:C1DE4C67D6C56C1F7A9695538F8B694D@in.WebX.maYIadrTaRb...
> Then I would change that declaration to this
>
> pi = Atn(1) * 4
>
> Joe
>
> Marko Rogic wrote in message
> news:103C1B846966B4E9CC0378696ADC8028@in.WebX.maYIadrTaRb...
> > I've declared it like this:
> >
> > Public Const pi As Double = 3.141592654
> >
> >
> >
> > "Joe Sutphin" wrote in message
> > news:63C5392CB589E89933D452EADF049567@in.WebX.maYIadrTaRb...
> > > What are you using for the value of Pi?
> > >
> > > Pi = Atn(1) * 4
> > >
> > > Joe
> > >
> > > Marko Rogic wrote in message
> > > news:C9242FE8D3165510EB5201C4F4FF63F4@in.WebX.maYIadrTaRb...
> > > > This is a little sub that I use for calculating mass of circular
> > objects.
> > >
> >
>
> --------------------------------------------------------------------------
> > > --
> > > > ---
> > > > Public Sub Circle()
> > > >
> > > > Dim d As Double
> > > > Dim h As Double
> > > >
> > > > On Error GoTo ErrorControl
> > > > d = txtDiameter.Text
> > > > h = txtHeight.Text
> > > > txtMass.Text = (((pi * d * d / 4) * h) / 1000000000)
> > > > Exit Sub
> > > >
> > > > ErrorControl:
> > > > If txtDiameter.Text = "" Then
> > > > MsgBox "Enter Diameter!", vbOKOnly, "Error Control"
> > > > txtDiameter.SetFocus
> > > > ElseIf txtHeight.Text = "" Then
> > > > MsgBox "Enter Height!", vbOKOnly, "Error Control"
> > > > txtHeight.SetFocus
> > > > End If
> > > > End Sub
> > >
> >
>
> --------------------------------------------------------------------------
> > > --
> > > > ---
> > > > I believe that it works OK if I enter values for Diameter and Height
> > > larger
> > > > then "8" (I'm nott 100% sure I didn't try all the numbers). But if
the
> > > > number is smaller then "8" it doesn't return the correct value. It's
> > much
> > > > bigger then it should be.
> > > >
> > > > What is wrong here? Should I declare "d" and "h" as something else
> then
> > > > Double.
> > > >
> > > > Thanks, Marko.
> > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
0 Likes
Message 9 of 10

Anonymous
Not applicable
You 'd best look in the VBA Help for the Format function and example.

MyStr = Format(5459.4, "##,##0.00") ' Returns "5,459.40".

--
Henk
0 Likes
Message 10 of 10

Anonymous
Not applicable
Thanks Henk.

"Henk Loonstra" wrote in message
news:0785D5457C092E69222D64421326858C@in.WebX.maYIadrTaRb...
> You 'd best look in the VBA Help for the Format function and example.
>
> MyStr = Format(5459.4, "##,##0.00") ' Returns "5,459.40".
>
> --
> Henk
>
>
0 Likes