Specific rounding question

Specific rounding question

Anonymous
Not applicable
478 Views
12 Replies
Message 1 of 13

Specific rounding question

Anonymous
Not applicable
I am measuring room sizes and I have been instructed to only use X'-0" X'-4"
X'-6" or X'-8"

How would I search my string value for any inches and then round to one of
those inch values.



Thanks

Here is some sample code:
Dim pt1 As Variant
Dim pt2 As Variant
pt1 = ThisDrawing.Utility.GetPoint(, "Pick Lower Left Corner of Room...")
pt2 = ThisDrawing.Utility.GetPoint(, "Pick Upper Right Corner of Room...")

Dim line1 As AcadLine
Set line1 = ThisDrawing.ModelSpace.AddLine(pt1, pt2)

Dim valueAsStrX As String
Dim valueAsStrY As String
Dim unit As Long


Dim lineDelta As Variant
lineDelta = line1.Delta
Dim deltaX As Variant
Dim deltaY As Variant

deltaX = lineDelta(0)
deltaY = lineDelta(1)

line1.Delete
unit = acArchitectural

valueAsStrX = ThisDrawing.Utility.RealToString(deltaX, unit, 0)
valueAsStrY = ThisDrawing.Utility.RealToString(deltaY, unit, 0)

Thanks
0 Likes
479 Views
12 Replies
Replies (12)
Message 2 of 13

Anonymous
Not applicable
It sounds like you need to do more than just round.
Of course first step is isolate your inch value,
then if it's < 4 set = 4
if >4 and <6 set = 6
if >6 and <8 set = 8
if >8 ??? here, are you going to round up to the next foot?
or >8 and <10 set = 8...and > 10 round to next foot, in which case you need
to get your foot string value and increment that too.

"Eric Stewart" wrote in message
news:BB81211EB622ADA09AFD760976D0BEE2@in.WebX.maYIadrTaRb...
> I am measuring room sizes and I have been instructed to only use X'-0"
X'-4"
> X'-6" or X'-8"
>
> How would I search my string value for any inches and then round to one of
> those inch values.
>
>
>
> Thanks
>
> Here is some sample code:
> Dim pt1 As Variant
> Dim pt2 As Variant
> pt1 = ThisDrawing.Utility.GetPoint(, "Pick Lower Left Corner of Room...")
> pt2 = ThisDrawing.Utility.GetPoint(, "Pick Upper Right Corner of Room...")
>
> Dim line1 As AcadLine
> Set line1 = ThisDrawing.ModelSpace.AddLine(pt1, pt2)
>
> Dim valueAsStrX As String
> Dim valueAsStrY As String
> Dim unit As Long
>
>
> Dim lineDelta As Variant
> lineDelta = line1.Delta
> Dim deltaX As Variant
> Dim deltaY As Variant
>
> deltaX = lineDelta(0)
> deltaY = lineDelta(1)
>
> line1.Delete
> unit = acArchitectural
>
> valueAsStrX = ThisDrawing.Utility.RealToString(deltaX, unit, 0)
> valueAsStrY = ThisDrawing.Utility.RealToString(deltaY, unit, 0)
>
> Thanks
>
>
0 Likes
Message 3 of 13

Anonymous
Not applicable
Oh sure. The If Then stuff is simple. How would one go about isolating the
lst three characters of the string?


"Mark Propst" wrote in message
news:945C1887B43F3C7230154BC2F83D4485@in.WebX.maYIadrTaRb...
> It sounds like you need to do more than just round.
> Of course first step is isolate your inch value,
> then if it's < 4 set = 4
> if >4 and <6 set = 6
> if >6 and <8 set = 8
> if >8 ??? here, are you going to round up to the next foot?
> or >8 and <10 set = 8...and > 10 round to next foot, in which case you
need
> to get your foot string value and increment that too.
>
> "Eric Stewart" wrote in message
> news:BB81211EB622ADA09AFD760976D0BEE2@in.WebX.maYIadrTaRb...
> > I am measuring room sizes and I have been instructed to only use X'-0"
> X'-4"
> > X'-6" or X'-8"
> >
> > How would I search my string value for any inches and then round to one
of
> > those inch values.
> >
> >
> >
> > Thanks
> >
> > Here is some sample code:
> > Dim pt1 As Variant
> > Dim pt2 As Variant
> > pt1 = ThisDrawing.Utility.GetPoint(, "Pick Lower Left Corner of
Room...")
> > pt2 = ThisDrawing.Utility.GetPoint(, "Pick Upper Right Corner of
Room...")
> >
> > Dim line1 As AcadLine
> > Set line1 = ThisDrawing.ModelSpace.AddLine(pt1, pt2)
> >
> > Dim valueAsStrX As String
> > Dim valueAsStrY As String
> > Dim unit As Long
> >
> >
> > Dim lineDelta As Variant
> > lineDelta = line1.Delta
> > Dim deltaX As Variant
> > Dim deltaY As Variant
> >
> > deltaX = lineDelta(0)
> > deltaY = lineDelta(1)
> >
> > line1.Delete
> > unit = acArchitectural
> >
> > valueAsStrX = ThisDrawing.Utility.RealToString(deltaX, unit, 0)
> > valueAsStrY = ThisDrawing.Utility.RealToString(deltaY, unit, 0)
> >
> > Thanks
> >
> >
>
>
0 Likes
Message 4 of 13

Anonymous
Not applicable
Eric,
look at the Left Right and Mid functions as well as Left$, Right$ etc
What do the 1st three characters have to do with what you were talking
about?
You will have to see what form the string you have to start with will have.
Where do you get the string from? a dimension text, a distance command, a
text entity? In any case the format may have an \" for the inch mark. you
may need to find that using Right for example, then step forward through the
string to see if there's a fraction to deal with, then forward again to get
the inch value etc.
each string may vary depending on what your actual input is.
1'-2 13/16", "1'-2 13/16\"", 2'-4", 2' 4", "2' 4\"", etc.
I don't think you can count on the number of characters to find your inch
value you may have to find the inch mark and it's preceeding space character
(or dash) and deal with that.

does that make any sense?
Mark
0 Likes
Message 5 of 13

Anonymous
Not applicable
> What do the 1st three characters have to do with what you were talking
> about?
That was a typo. I meant to type lat three characters 1st looks a lot like
lst.

Thanks again for your help
0 Likes
Message 6 of 13

Anonymous
Not applicable
It may be easier to convert the string representation into a real number
with the Utility.DistanceToReal method. Then you could perform the
"rounding" calcs using numbers instead of parsing a string.
--
Bobby C. Jones
www.AcadX.com
0 Likes
Message 7 of 13

Anonymous
Not applicable
Well, I understand typos - it's monday after all, but still you probably
can't depend on the lat three characters being the value you need. But do
you have enough of an idea now of how to proceed or you need more?

"Eric Stewart" wrote in message
news:E03CC5F9F03AB93ADFA793D86A9D761B@in.WebX.maYIadrTaRb...
> > What do the 1st three characters have to do with what you were talking
> > about?
> That was a typo. I meant to type lat three characters 1st looks a lot
like
> lst.
>
> Thanks again for your help
>
>
0 Likes
Message 8 of 13

Anonymous
Not applicable
I can't find any info in the help file about Left Mid and Right functions.
I understand the principle though if I can find documentation. I think I've
done something similar in JavaScript.
0 Likes
Message 9 of 13

Anonymous
Not applicable
That would be ideal if I could use 10" measurements. However, I have been
instructed that WE do not show a room dimension with 10". This is for some
Sales type sheets and 10" is not desired.

Thanks
0 Likes
Message 10 of 13

Anonymous
Not applicable
Which help file are you looking in? If you're in autocad, the help menu has
a submenu Developer help that will take you to areas pertinent to lisp and
vba in autocad issues, however, some things you'll do in vb(a) are visual
basic issues, so for help on that, go to the vbaide (alt + f11) and use the
help menu there. That will take you to the microsoft visual basic specific
help files. They are completely different help systems. There you will
find Left, Right, Mid, InStr, etc for string handling functions in vb(a)
(and Format to format the result string to what you want to see)
However, Bobby Jone's idea was the best - convert to real and do your
"rounding" there, then reconvert to string to display.

"Eric Stewart" wrote in message
news:7632F295679373FF53B34F418BBCCE89@in.WebX.maYIadrTaRb...
> I can't find any info in the help file about Left Mid and Right functions.
> I understand the principle though if I can find documentation. I think
I've
> done something similar in JavaScript.
>
>
>
>
>
0 Likes
Message 11 of 13

Anonymous
Not applicable
Eric,

You can still use Bobby's excellent suggestion. You just have to compose
your own "rounding logic" based on what your output needs are.
As you are aware, you're not really 'rounding' in a mathematical sense.
You're converting some various inputs to some various desired outputs. The
logic of how you want to convert the inputs to outputs is for you to
ecide( per one of my earlier posts).

His point is that you can do the conversions easier using numbers than by
parsing strings, but you're still going to have to write a conversion
algorithm to change a given input value to an output value based on your
requirements. Whether those values are strings or numbers is not important,
it just might be a few less lines of codes to convert the numbers than to
parse the strings looking for inch signs and the like.

What is the source of your input? Is the user picking a dimension entity?
text entity? entering points for corners of a room? selecting a polyline
representing a room? something else?
What is your output? Placing a piece of text on the drawing? filling a
textbox in a dialog box? something else?
Mark
0 Likes
Message 12 of 13

SteveStone9194
Community Visitor
Community Visitor
You're making this issue way too difficult. Create a dimensions style with the rounding set to 2" - AutoCAD takes it from there.

Steve Stone
ES Tech
0 Likes
Message 13 of 13

SteveStone9194
Community Visitor
Community Visitor
Sorry - that won't work. I re-read your message and saw that 2" & 10" aren't valid.
0 Likes