DesignCAD 2019 and DesignCAD 3D Max 2019 now available for sale! OR

Issue with the Round() function
Read 2328 times
* December 30, 2017, 08:38:32 AM
Hey guys, I'm having an issue with the Round() statement not appearing to work, at least not as I expect. I've been trying to use a For next loop counter variable as a whole integer but it keeps returning to 3 decimal places. Granted, they're zero's but, All I want is the integer.
Ultimately I'm converting it into a string and i could play text string games with it and strip out the decimal and the zeros but that seems like a lot of code for something that should be a simple built in function

Window 10, 30 'Open a text window 10 lines x 30 characters.

For j = 1 To 6 'Print numbers 1-6 in the window.
Print Round(j)

Next j

Any thoughts?


* December 30, 2017, 11:25:11 AM
OK... Now this is getting weird. I'm also having issue with some of the string functions. I cut and pasted the example out of the documentation for the MKS$() function and it's returning some weird stuff.
Window 10, 30 'Open a text window 10 lines x 30 characters.
On Error goto ErrorHandler
x = 1.111
      a$ = MKS$(x) 'convert the number to a string
      print "[" + a$ + "]"
      y = CVS(a$)   'convert the string back to a number
      print y
message "An Error Occured"

Here's the output...


December 30, 2017, 03:43:30 PM
What version of DesignCAD? What version of Windows? 32 or 64 bit?


DesignCAD user since 1987

December 30, 2017, 04:58:16 PM

For your starting post:
Add the following somewhere near the start of the code...
Code: [Select]
precision 0
That will get rid of the trailing zeros. The default precision is 3 (so this is used if you don't stipulate a precision), that's why you got them. Note that precision only affects how numbers are displayed, not the actual value.

For your 2nd post:
My understanding is that converting numbers to strings doesn't write it out in words. It presents it in some computer language (an "8-character string"), as shown in your image.

To convert a string to numeric values use val(a$). It doesn't convert words to numbers but it can evaluate symbols, like foot and inches (' and ") and those for degree-minute-second (eg 1D1M1S, ie, 1 degree, 1 minute, 1 second). So if your code says a$="1' " (I put a space between the foot symbol and the ending quotes, for clarity) then val(a$) equals 1 if using foot based units, 12 if using inch based units, 30.480 if using cm based units (and the default precision of 3 - note that when converting string to values the current precision can affect the actual value), etc. (use sys(1100) to set the current drawing units in a macro [0 = unitless, 1 = inches, 2 = feet, 3 = miles, 4 = mm, 5 = cm, 6 = m, 7 = km]).

To convert a number back into a sting just assign it (eg, a$=a  <<note that a would have been assigned a numeric value earlier in the code>>). This would not convert the number into words but would make the number usable in text strings, as opposed to usable in calculations.

« Last Edit: December 30, 2017, 05:01:44 PM by Lar »


December 31, 2017, 03:28:14 PM
Also, don't forget we now have the Format statement -- this will let you format numbers in a variety of ways.

Lar is correct, MKS$ doesn't convert a floating point number to a *human-readable* string -- it just stores the raw bytes of the number in an 8-character string for compact storage in a data file. Depending on the number there may be unprintable characters in that string. CVS is used to convert that string back into the original number.
« Last Edit: December 31, 2017, 03:31:40 PM by DrollTroll »

25 years with DesignCAD

* December 31, 2017, 04:02:51 PM
Dr Pr... It's 32 bit Windows and I'm using DesignCAD 3D MAX 2018.

Lar... I headed down the "Precision" road but.... I tried to change it in the drawing I applied the Macro too, NOT in the macro itself. I'll give that a shot to deal with the trailing zero's.
As for the converting numbers to strings, what I'm trying to accomplish is use the For Next counter to set the text property in a Text Entity. In other words, I want to number the rows and columns of lines I'm drawing. In my testing when I try to convert a number to a string I get gibberish, as shown in my other post but... when I convert the string back to a number, it's correct.

Droll Troll... The documentation must be old then. The example in the doc's is what I tried, and why I was confused.  I just looked at the Format statement and it looks like it will do what I need.

Thanks all and Happy New Year