Search code examples
vbaautocad

Splitting a Variable's Output Value Into 2 Lines in Sheet


I am working on a program/macro that intertwines VBA with AutoCAD Mechanical 2020. Based on a userform input, the below variable "cw" is stored to output into the sheet space based on the below line of code. It currently outputs in a single line and I am needing it to output into 2 different lines without actually deleting the value of the variable "cw".

Lines of Code that shows variable "cw":

enter image description here

How it currently outputs in sheet space:

enter image description here

How I need it to outputs in sheet space:

enter image description here


Solution

  • As mentioned in the comments, you will need to split apart your counterweight text and reformat it as needed. You will also use Format Codes within the reformatted text to get the alignment correct. Currently, the text is like this:

       cw = "198,400 + 551,200 + 1,222,333 lbs"
    

    and you need to end up with the text like this:

       nw = "1,222,333 lbs.\P551,200 lbs.\P198,400 lbs."
    

    Notice the embedded Format Codes. Finally, here is the code to make this happen:

       cw = "198,400 + 551,200 + 1,222,333 lbs"
       
       nw = Replace(cw, " +", "")
       nw = Replace(nw, " lbs", "")
       nw = Split(nw, " ")
       nw = nw(2) & " lbs." & "\P" & nw(1) & " lbs." & "\P" & nw(0) & " lbs."
       
       Set text3 = ThisDrawing.PaperSpace.AddMText(textpoint3, 5, "Counterweight Package:")
       text3.AttachmentPoint = acAttachmentPointBottomRight
       Set text4 = ThisDrawing.PaperSpace.AddMText(textpoint4, 5, nw)
       text4.AttachmentPoint = acAttachmentPointBottomRight
    

    This approach will work for any number of weights.