TheSwamp
Code Red => VB(A) => Topic started by: Humbertogo 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
:-D :ugly:
Select Case dblangle
Case 0, 135, 180, 225
-
what exactly are you trying to do?
-
Angles are measured in Radians, so that might be giving you a problem
-
dblradians = ThisDrawing.Utility.AngleFromXAxis(PolySp, PolyEp)
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
-
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 ?
-
dblangle = dbl radians* (180 / PI)'conv radians to Degree
dblAng is my return value
-
If you wanted to set them all to 0, why not dblAng = 0 ?
you right but i can not select 135 and 225
-
ok, I tried to duplicate your problem, and I think your problem is the decimal point.
Option Explicit
Sub 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 cmdrduh
Private Function DtoR(d As Double) ' Degrees to Radians
Const PI = 3.14159265
DtoR = (PI * d) / 180
End Function
Private Function RtoD(r As Double) ' Radians to Degrees
Const PI = 3.14159265
RtoD = (180 * r) / PI
End 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
-
til I used CInt() to convert the double to and integer
Thanks
-
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.
-
Try using round of the returned angle value.
MyValue = MyReturnedAngle
MyValue = Round(MyValie, 3) will put you are 3 decimals. Adjust your case accordingly.
-
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
-
I used both of these to test that theory. I like the Round better.
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
-
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