Hello,
I have macro which calculate area and perimeter. But I need what this will shows two numbers after dot. (example 0.25 m, NOT 0.254354 m)
Could anybody help me? thank you
Sub doCalculateArea()On Error Resume NextDim s As Shape, sr As ShapeRange, s2 As ShapeDim oldUnit As cdrUnit, newUnit As cdrUnitDim strUnit As String, strArea As StringDim strMessage As String
Dim myOptionUnit, myOptionInfo
ActiveDocument.ReferencePoint = cdrCenter'=== DEFAULT UNITnewUnit = cdrMeterstrUnit = "m"strArea = "²" 'SUBSCRIPT '2'
myOptionUnit = InputBox("Enter Value 0 (m), 1 (inch), 2 (cm)", "Change Unit:", 0)myOptionInfo = InputBox("Enter Value 0 (Dialog Box), 1 (Create Text In Object Selected)", "Option for Info Area:", 0)
If myOptionUnit = 1 Then newUnit = cdrInch strUnit = "inch"ElseIf myOptionUnit = 2 Then newUnit = cdrCentimeter strUnit = "cm"End If
'=== CHANGE UNIT'For Reset to Recent Document UnitoldUnit = ActiveDocument.UnitActiveDocument.Unit = newUnit
Set sr = ActiveSelectionRangeFor Each s In sr 'IF NOT BITMAP & NOT CURVES MUST BE CONVERT TO CURVE If s.Type <> cdrBitmapShape And s.Type <> cdrCurveShape Then s.ConvertToCurves strMessage = "" & s.Name & vbCrLf & "S: " & s.Curve.Area & " " & strUnit & strArea & vbCrLf & "P: " & s.Curve.Length & " " & strUnit & vbCrLf ' REMOVE ' BEFORE MsgBox If you want to Get Info By Dialog Message '========= START OPTION INFO If myOptionInfo = 0 Then MsgBox "" & s.Name & vbCrLf & "Area : " & s.Curve.Area & " " & strUnit & strArea & vbCrLf & "P: " & s.Curve.Length & " " & strUnit & strArea & vbCrLf Else '========== START CREATE INFO TEXT If s.Type = cdrCurveShape Then 'CREATE INFO AREA IN ACTIVE LAYER WITH ARTISTIC TEXT Set s2 = ActiveLayer.CreateArtisticText(0, 0, strMessage, , , , 6) 'ALIGN TEXT INFO AREA TO CURRENT SHAPE s2.AlignToShape cdrAlignHCenter + cdrAlignVCenter, s Set s2 = Nothing End If '========== END CREATE INFO TEXT End If '========= END OPTION INFO Next s
'RESET TO RECENT DEFAULT UNITActiveDocument.Unit = oldUnit
End Sub
Look at formatnumber function
for sample look here
https://community.coreldraw.com/talk/coreldraw_graphics_suite_x7/f/corel-connect-x7/47903/macro-round-up-or-down/229857#229857
You can look at using the Format function in VBA. Here's an example:
Sub test_format() Dim s As Shape Set s = ActiveShape MsgBox "Object Width: " & Format(s.SizeWidth, "0.##") & vbCrLf & vbCrLf & "Object Height: " & Format(s.SizeHeight, "0.##") End Sub
You can find documentation and examples online to help you understand how to use the format string to get different types of formatting.