### Author Topic: select case Angle  (Read 2536 times)

0 Members and 1 Guest are viewing this topic.

#### Humbertogo

• Guest
##### select case Angle
« on: July 17, 2007, 03:18:05 PM »
i try to make a simple selection of a different angles
but when  dblangle = 135 or 225 nothing is select
:ugly:
Select Case dblangle

Case 0, 135, 180, 225

#### David Hall

• Automatic Duh Generator
• King Gator
• Posts: 4042
##### Re: select case Angle
« Reply #1 on: July 17, 2007, 03:22:41 PM »
what exactly are you trying to do?
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

#### David Hall

• Automatic Duh Generator
• King Gator
• Posts: 4042
##### Re: select case Angle
« Reply #2 on: July 17, 2007, 03:23:14 PM »
Angles are measured in Radians, so that might be giving you a problem
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

#### Humbertogo

• Guest
##### Re: select case Angle
« Reply #3 on: July 17, 2007, 03:26:56 PM »
dblangle = dblradians * (180 / PI)

Select Case dblangle
Case 0, 135, 180, 225
dblAng = 0 * (PI / 180)

i just try to convert  135, 180, 225 degreed to 0

#### David Hall

• Automatic Duh Generator
• King Gator
• Posts: 4042
##### Re: select case Angle
« Reply #4 on: July 17, 2007, 03:29:17 PM »
I dont know if you miss typed, but what is dblAng vs dblangles?  If you wanted to set them all to 0, why not dblAng = 0  ?
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

#### Humbertogo

• Guest
##### Re: select case Angle
« Reply #5 on: July 17, 2007, 03:32:43 PM »

dblAng is my return value

#### Humbertogo

• Guest
##### Re: select case Angle
« Reply #6 on: July 17, 2007, 03:34:53 PM »
Quote
If you wanted to set them all to 0, why not dblAng = 0  ?

you right but i can not select 135 and 225

#### David Hall

• Automatic Duh Generator
• King Gator
• Posts: 4042
##### Re: select case Angle
« Reply #7 on: July 17, 2007, 03:41:02 PM »
ok, I tried to duplicate your problem, and I think your problem is the decimal point.

Code: [Select]
`Option ExplicitSub Example_AngleFromXAxis()    ' This example finds the angle, in radians, between the X axis    ' and a line defined by two points.        Dim pt1(0 To 2) As Double    Dim pt2(0 To 2) As Double    Dim retAngle As Double        pt1(0) = 2: pt1(1) = 5: pt1(2) = 0    pt2(0) = 5: pt2(1) = 2: pt2(2) = 0        ' Return the angle    retAngle = ThisDrawing.Utility.AngleFromXAxis(pt1, pt2)    retAngle = RtoD(retAngle)'*****   added by cmdrduh    ' Create the line for a visual reference'*****   added by cmdrduh    Dim intretangle As Integer    intretangle = CInt(retAngle)    Select Case intretangle    Case 0    MsgBox "0"    Case 315    MsgBox "315"    End Select    ' end of  *****   added by cmdrduh        Dim lineObj As AcadLine    Set lineObj = ThisDrawing.ModelSpace.AddLine(pt1, pt2)    ZoomAll        ' Display the angle found    MsgBox "The angle in radians between the X axis and the line is " & retAngle, , "AngleFromXAxis Example"    End Sub'*****   added by cmdrduhPrivate Function DtoR(d As Double)      ' Degrees to Radians      Const PI = 3.14159265      DtoR = (PI * d) / 180End FunctionPrivate Function RtoD(r As Double)      ' Radians to Degrees      Const PI = 3.14159265      RtoD = (180 * r) / PIEnd Function`
this function came out of help, and I added the select case part.  I could not get it to find the 315 degree line, til I used CInt() to convert the double to and integer.  You could probably do something similiar, or broaden your select case
« Last Edit: July 17, 2007, 03:44:17 PM by CmdrDuh »
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

#### Humbertogo

• Guest
##### Re: select case Angle
« Reply #8 on: July 17, 2007, 03:57:47 PM »
Quote

til I used CInt() to convert the double to and integer

Thanks

#### David Hall

• Automatic Duh Generator
• King Gator
• Posts: 4042
##### Re: select case Angle
« Reply #9 on: July 17, 2007, 04:16:45 PM »
there is probably a much better way to do that, but Im too tired right now to think.  Maybe a guru can lend a hand here.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

#### DaveW

• Guest
##### Re: select case Angle
« Reply #10 on: July 17, 2007, 10:20:07 PM »
Try using round of the returned angle value.

MyValue = MyReturnedAngle

MyValue = Round(MyValie, 3) will put you are 3 decimals. Adjust your case accordingly.

#### Bryco

• Water Moccasin
• Posts: 1855
##### Re: select case Angle
« Reply #11 on: July 17, 2007, 11:29:59 PM »
Definately a rounding problem, although below works I would rather set the angle first
Select Case dblAngle
Case -0.00001 To 0.000001, 134.99999 To 135.0001, 179.00001 To 180.00001, 224.99999 To 225.000001
Debug.Print dblAngle
End Select

#### David Hall

• Automatic Duh Generator
• King Gator
• Posts: 4042
##### Re: select case Angle
« Reply #12 on: July 18, 2007, 10:39:29 AM »
I used both of these to test that theory.  I like the Round better.
Code: [Select]
`retAngle = Round(retAngle, 0)retAngle = retAngle \ 1`
the first rounded with no decimal places, (duh)
but the second one I used Integer Division, which would drop the decimal place as part of the division
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

#### Humbertogo

• Guest
##### Re: select case Angle
« Reply #13 on: July 19, 2007, 03:54:57 AM »

Code: [Select]
`                retAngle = ThisDrawing.Utility.AngleFromXAxis(PolySp, PolyEp)                retAngle = RtoD(retAngle)                intretangle = CInt(retAngle)              'uses the Mod operator to divide two numbers and return only the remainder.               intretangle = intretangle Mod 90`