#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Forms

Hi Everybody, I am using Excel 2002 and I have only been using vb for a short
while

I need to draw arcs and I have Pick-up this code on the net which does not
run. The error is Run-time error €˜424: Object required. I think its some
thing to do with Form1 but I do not understand about Forms and I cannot find
anything about forms in my ref books apart from Userforms.

Can somebody please explain?

Many Thanks

Private Declare Function Arc Lib "gdi32" (ByVal hdc As Long, ByVal X1 As
Long, _
ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long,
ByVal Y3 As Long, _
ByVal X4 As Long, ByVal Y4 As Long) As Long


Private Sub Form_Load()
Dim rval As Long
'play about with the values
rval = Arc(Form1.hdc, 100, 450, 300, 10, 250, 100, 100, 150)

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Forms

That code is for VB the language, where the work is done on a form.

I don't see any argument on it to specify a radius, so I would go back to
the code offered previously and see if you can't figure out how to translate
the parameters you have into the parameters you need.

--
Regards,
Tom Ogilvy



"PraxisPete" wrote in message
...
Hi Everybody, I am using Excel 2002 and I have only been using vb for a

short
while

I need to draw arcs and I have Pick-up this code on the net which does not
run. The error is Run-time error '424': Object required. I think its some
thing to do with Form1 but I do not understand about Forms and I cannot

find
anything about forms in my ref books apart from Userforms.

Can somebody please explain?

Many Thanks

Private Declare Function Arc Lib "gdi32" (ByVal hdc As Long, ByVal X1 As
Long, _
ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long,
ByVal Y3 As Long, _
ByVal X4 As Long, ByVal Y4 As Long) As Long


Private Sub Form_Load()
Dim rval As Long
'play about with the values
rval = Arc(Form1.hdc, 100, 450, 300, 10, 250, 100, 100, 150)

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Forms

Thank you for your comments Tom,

I have found this code which meets my requirements i.e. has an argument for
Radius and I can provide the position for the centre, start angle and sweep
angle, this would be perfect. Is there anyway this can run, or is there a
similar tool or addin ?

Thanks in anticipation

Declare Function AngleArc Lib "gdi32.dll" (ByVal hdc As Long, ByVal x As
Long,
ByVal y As Long, ByVal dwRadius As Long, ByVal eStartAngle As Single, ByVal
eSweepAngle As Single) As Long


' Draw an arc formed by the upper half of a circle (from 0 to 180
' degrees counterclockwise). The circle is centered at (100, 150) and has a
radius
' of 50. The arc is drawn using the solid black stock pen.
Dim hpen As Long ' handle to the black stock pen
Dim holdpen As Long ' handle to Form1's previously selected pen
Dim retval As Long ' return value

' Get the solid black stock pen and select it for use in Form1.
hpen = GetStockObject(BLACK_PEN) ' get the pen's handle
holdpen = SelectObject(Form1.hDC, hpen) ' select the pen

' Make sure arcs are drawn going counterclockwise
retval = SetArcDirection(Form1.hDC, AD_COUNTERCLOCKWISE)
' Draw the arc
retval = AngleArc(Form1.hDC, 100, 150, 50, 0, 180)

' Select Form1's previous pen to restore the "defaults".
retval = SelectObject(Form1.hDC, holdpen) ' select the old pen


"Tom Ogilvy" wrote:

That code is for VB the language, where the work is done on a form.

I don't see any argument on it to specify a radius, so I would go back to
the code offered previously and see if you can't figure out how to translate
the parameters you have into the parameters you need.

--
Regards,
Tom Ogilvy



"PraxisPete" wrote in message
...
Hi Everybody, I am using Excel 2002 and I have only been using vb for a

short
while

I need to draw arcs and I have Pick-up this code on the net which does not
run. The error is Run-time error '424': Object required. I think its some
thing to do with Form1 but I do not understand about Forms and I cannot

find
anything about forms in my ref books apart from Userforms.

Can somebody please explain?

Many Thanks

Private Declare Function Arc Lib "gdi32" (ByVal hdc As Long, ByVal X1 As
Long, _
ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long,
ByVal Y3 As Long, _
ByVal X4 As Long, ByVal Y4 As Long) As Long


Private Sub Form_Load()
Dim rval As Long
'play about with the values
rval = Arc(Form1.hdc, 100, 450, 300, 10, 250, 100, 100, 150)

End Sub




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 318
Default Forms

This code also will only work with traditional VB rather than VBA. This is
because in VBA the UserForms do not have the hdc property for you to get the
Handle to the form. Have you considered using the arc object in Excel instead.

Alok Joshi

"PraxisPete" wrote:

Thank you for your comments Tom,

I have found this code which meets my requirements i.e. has an argument for
Radius and I can provide the position for the centre, start angle and sweep
angle, this would be perfect. Is there anyway this can run, or is there a
similar tool or addin ?

Thanks in anticipation

Declare Function AngleArc Lib "gdi32.dll" (ByVal hdc As Long, ByVal x As
Long,
ByVal y As Long, ByVal dwRadius As Long, ByVal eStartAngle As Single, ByVal
eSweepAngle As Single) As Long


' Draw an arc formed by the upper half of a circle (from 0 to 180
' degrees counterclockwise). The circle is centered at (100, 150) and has a
radius
' of 50. The arc is drawn using the solid black stock pen.
Dim hpen As Long ' handle to the black stock pen
Dim holdpen As Long ' handle to Form1's previously selected pen
Dim retval As Long ' return value

' Get the solid black stock pen and select it for use in Form1.
hpen = GetStockObject(BLACK_PEN) ' get the pen's handle
holdpen = SelectObject(Form1.hDC, hpen) ' select the pen

' Make sure arcs are drawn going counterclockwise
retval = SetArcDirection(Form1.hDC, AD_COUNTERCLOCKWISE)
' Draw the arc
retval = AngleArc(Form1.hDC, 100, 150, 50, 0, 180)

' Select Form1's previous pen to restore the "defaults".
retval = SelectObject(Form1.hDC, holdpen) ' select the old pen


"Tom Ogilvy" wrote:

That code is for VB the language, where the work is done on a form.

I don't see any argument on it to specify a radius, so I would go back to
the code offered previously and see if you can't figure out how to translate
the parameters you have into the parameters you need.

--
Regards,
Tom Ogilvy



"PraxisPete" wrote in message
...
Hi Everybody, I am using Excel 2002 and I have only been using vb for a

short
while

I need to draw arcs and I have Pick-up this code on the net which does not
run. The error is Run-time error '424': Object required. I think its some
thing to do with Form1 but I do not understand about Forms and I cannot

find
anything about forms in my ref books apart from Userforms.

Can somebody please explain?

Many Thanks

Private Declare Function Arc Lib "gdi32" (ByVal hdc As Long, ByVal X1 As
Long, _
ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long,
ByVal Y3 As Long, _
ByVal X4 As Long, ByVal Y4 As Long) As Long


Private Sub Form_Load()
Dim rval As Long
'play about with the values
rval = Arc(Form1.hdc, 100, 450, 300, 10, 250, 100, 100, 150)

End Sub




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Forms

This will draw an arc with the center at the upper left corner of D5 and a
radius of 50. It draws a 90 degree arc (I am speaking from a reference of
the top of the arc being at top of the sheet). I then adjust it to be 135
degrees. The degrees for adjustment appear to be measured from horizontal
with counter clockwise being positive. So 90 from the top is 0 degress for
adjustment. However, that establishes the end of the Arc. The actual Arc
is extended in a clockwise direction. So if I had done 135 rather than -
45, I get an arc of 315 degress measured from the top (or - 45 from top).

You can then turn on the macro recorder and use the rotate command if you
don't want the arc to start from something other than the top. Also look at
the flip command (vertical and horizontal) to get a different orientation.

Sub Macro4()
Dim sh As Shape
Dim cTop As Long
Dim cLeft As Long
Dim rad As Long
cTop = Range("D5").Top
cLeft = Range("D5").Left
rad = Range("D5").Width
Set sh = ActiveSheet.Shapes.AddShape(msoShapeArc, cLeft, cTop - rad, rad,
rad)
sh.Adjustments(2) = -45
'sh.Adjustments(2) = 135
End Sub

--
Regards,
Tom Ogilvy




"PraxisPete" wrote in message
...
Thank you for your comments Tom,

I have found this code which meets my requirements i.e. has an argument

for
Radius and I can provide the position for the centre, start angle and

sweep
angle, this would be perfect. Is there anyway this can run, or is there a
similar tool or addin ?

Thanks in anticipation

Declare Function AngleArc Lib "gdi32.dll" (ByVal hdc As Long, ByVal x As
Long,
ByVal y As Long, ByVal dwRadius As Long, ByVal eStartAngle As Single,

ByVal
eSweepAngle As Single) As Long


' Draw an arc formed by the upper half of a circle (from 0 to 180
' degrees counterclockwise). The circle is centered at (100, 150) and has

a
radius
' of 50. The arc is drawn using the solid black stock pen.
Dim hpen As Long ' handle to the black stock pen
Dim holdpen As Long ' handle to Form1's previously selected pen
Dim retval As Long ' return value

' Get the solid black stock pen and select it for use in Form1.
hpen = GetStockObject(BLACK_PEN) ' get the pen's handle
holdpen = SelectObject(Form1.hDC, hpen) ' select the pen

' Make sure arcs are drawn going counterclockwise
retval = SetArcDirection(Form1.hDC, AD_COUNTERCLOCKWISE)
' Draw the arc
retval = AngleArc(Form1.hDC, 100, 150, 50, 0, 180)

' Select Form1's previous pen to restore the "defaults".
retval = SelectObject(Form1.hDC, holdpen) ' select the old pen


"Tom Ogilvy" wrote:

That code is for VB the language, where the work is done on a form.

I don't see any argument on it to specify a radius, so I would go back

to
the code offered previously and see if you can't figure out how to

translate
the parameters you have into the parameters you need.

--
Regards,
Tom Ogilvy



"PraxisPete" wrote in message
...
Hi Everybody, I am using Excel 2002 and I have only been using vb for

a
short
while

I need to draw arcs and I have Pick-up this code on the net which does

not
run. The error is Run-time error '424': Object required. I think its

some
thing to do with Form1 but I do not understand about Forms and I

cannot
find
anything about forms in my ref books apart from Userforms.

Can somebody please explain?

Many Thanks

Private Declare Function Arc Lib "gdi32" (ByVal hdc As Long, ByVal X1

As
Long, _
ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As

Long,
ByVal Y3 As Long, _
ByVal X4 As Long, ByVal Y4 As Long) As Long


Private Sub Form_Load()
Dim rval As Long
'play about with the values
rval = Arc(Form1.hdc, 100, 450, 300, 10, 250, 100, 100, 150)

End Sub








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Forms

Thank you Tom and Alok I have got it cracked now and drawing just what I wanted
Its surprising to me just how much can be done in Excel if you now how.
Once again a big Thank you

"Tom Ogilvy" wrote:

This will draw an arc with the center at the upper left corner of D5 and a
radius of 50. It draws a 90 degree arc (I am speaking from a reference of
the top of the arc being at top of the sheet). I then adjust it to be 135
degrees. The degrees for adjustment appear to be measured from horizontal
with counter clockwise being positive. So 90 from the top is 0 degress for
adjustment. However, that establishes the end of the Arc. The actual Arc
is extended in a clockwise direction. So if I had done 135 rather than -
45, I get an arc of 315 degress measured from the top (or - 45 from top).

You can then turn on the macro recorder and use the rotate command if you
don't want the arc to start from something other than the top. Also look at
the flip command (vertical and horizontal) to get a different orientation.

Sub Macro4()
Dim sh As Shape
Dim cTop As Long
Dim cLeft As Long
Dim rad As Long
cTop = Range("D5").Top
cLeft = Range("D5").Left
rad = Range("D5").Width
Set sh = ActiveSheet.Shapes.AddShape(msoShapeArc, cLeft, cTop - rad, rad,
rad)
sh.Adjustments(2) = -45
'sh.Adjustments(2) = 135
End Sub

--
Regards,
Tom Ogilvy




"PraxisPete" wrote in message
...
Thank you for your comments Tom,

I have found this code which meets my requirements i.e. has an argument

for
Radius and I can provide the position for the centre, start angle and

sweep
angle, this would be perfect. Is there anyway this can run, or is there a
similar tool or addin ?

Thanks in anticipation

Declare Function AngleArc Lib "gdi32.dll" (ByVal hdc As Long, ByVal x As
Long,
ByVal y As Long, ByVal dwRadius As Long, ByVal eStartAngle As Single,

ByVal
eSweepAngle As Single) As Long


' Draw an arc formed by the upper half of a circle (from 0 to 180
' degrees counterclockwise). The circle is centered at (100, 150) and has

a
radius
' of 50. The arc is drawn using the solid black stock pen.
Dim hpen As Long ' handle to the black stock pen
Dim holdpen As Long ' handle to Form1's previously selected pen
Dim retval As Long ' return value

' Get the solid black stock pen and select it for use in Form1.
hpen = GetStockObject(BLACK_PEN) ' get the pen's handle
holdpen = SelectObject(Form1.hDC, hpen) ' select the pen

' Make sure arcs are drawn going counterclockwise
retval = SetArcDirection(Form1.hDC, AD_COUNTERCLOCKWISE)
' Draw the arc
retval = AngleArc(Form1.hDC, 100, 150, 50, 0, 180)

' Select Form1's previous pen to restore the "defaults".
retval = SelectObject(Form1.hDC, holdpen) ' select the old pen


"Tom Ogilvy" wrote:

That code is for VB the language, where the work is done on a form.

I don't see any argument on it to specify a radius, so I would go back

to
the code offered previously and see if you can't figure out how to

translate
the parameters you have into the parameters you need.

--
Regards,
Tom Ogilvy



"PraxisPete" wrote in message
...
Hi Everybody, I am using Excel 2002 and I have only been using vb for

a
short
while

I need to draw arcs and I have Pick-up this code on the net which does

not
run. The error is Run-time error '424': Object required. I think its

some
thing to do with Form1 but I do not understand about Forms and I

cannot
find
anything about forms in my ref books apart from Userforms.

Can somebody please explain?

Many Thanks

Private Declare Function Arc Lib "gdi32" (ByVal hdc As Long, ByVal X1

As
Long, _
ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As

Long,
ByVal Y3 As Long, _
ByVal X4 As Long, ByVal Y4 As Long) As Long


Private Sub Form_Load()
Dim rval As Long
'play about with the values
rval = Arc(Form1.hdc, 100, 450, 300, 10, 250, 100, 100, 150)

End Sub







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Forms Brenda New Users to Excel 1 April 27th 05 10:42 PM
RefEdits and normal forms / forms in a DLL David Welch Excel Programming 0 December 1st 04 03:49 PM
Forms that open from forms Azza Excel Programming 1 October 12th 04 10:54 PM
Calling Forms from Forms - Exit problems Stuart[_5_] Excel Programming 3 May 25th 04 06:50 AM
forms Steve Ketchum Excel Programming 0 October 8th 03 05:28 PM


All times are GMT +1. The time now is 12:42 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"