MsgBox justification

Discussion in 'AutoCAD' started by CADmike, Aug 4, 2004.

  1. CADmike

    CADmike Guest

    I am a beginner at VBA. Right now, I'm studying very simple functions and I couldn't find an answer for MsgBox output.
    My MsgBox has 2 lines of text. I figured out how to add a linefeed between the 2 lines. My question is if I can have the 2nd line of text center justified in the MsgBox? If so, how?
    Thanks in advance.
     
    CADmike, Aug 4, 2004
    #1
  2. CADmike

    Matt W Guest

    Use spaces until it looks good. :)
    The other option is to "build" one of your own using a form.

    --
    Matt W

    The difference between genius and stupidity is that genius has its limits.
    | I am a beginner at VBA. Right now, I'm studying very simple functions and
    I couldn't find an answer for MsgBox output.
    | My MsgBox has 2 lines of text. I figured out how to add a linefeed between
    the 2 lines. My question is if I can have the 2nd line of text center
    justified in the MsgBox? If so, how?
    | Thanks in advance.
     
    Matt W, Aug 4, 2004
    #2
  3. CADmike

    CADmike Guest

    Thanks, Matt. I considered that option. But if the lines of text are not the same length each time I run the function, then I would need to adjust how many spaces to add to the second line to make it look centered correctly. I just thought there was some syntax for justification that I was overlooking. I suppose I could compare the length of each string and append spaces to the second line before I use the MsgBox.
     
    CADmike, Aug 4, 2004
    #3
  4. Dim sLine1 As String, sLine2 As String, sTxt2 As String
    sLine1 = "Some longer text"
    sTxt2 = "Short text"
    sLine2 = Space(Len(sLine1) - Len(sTxt2) & sTxt2

    Check the arithmetic, but you get the idea.
    --
    John Goodfellow
    irtfnm
    use john at goodfellowassoc dot com


    the same length each time I run the function, then I would need to adjust
    how many spaces to add to the second line to make it look centered
    correctly. I just thought there was some syntax for justification that I was
    overlooking. I suppose I could compare the length of each string and append
    spaces to the second line before I use the MsgBox.
     
    John Goodfellow, Aug 4, 2004
    #4
  5. Of course, this code won't work so well for non-proportional fonts, but we
    all know that.

    --
    R. Robert Bell


    Dim sLine1 As String, sLine2 As String, sTxt2 As String
    sLine1 = "Some longer text"
    sTxt2 = "Short text"
    sLine2 = Space(Len(sLine1) - Len(sTxt2) & sTxt2

    Check the arithmetic, but you get the idea.
    --
    John Goodfellow
    irtfnm
    use john at goodfellowassoc dot com


    the same length each time I run the function, then I would need to adjust
    how many spaces to add to the second line to make it look centered
    correctly. I just thought there was some syntax for justification that I was
    overlooking. I suppose I could compare the length of each string and append
    spaces to the second line before I use the MsgBox.
     
    R. Robert Bell, Aug 4, 2004
    #5
  6. CADmike

    CADmike Guest

    Thanks, John. Your reply brings another question from me.
    It would seem to me that I would use 1/2 of the value from subtracting the length of string2 from string1 when appending
    spaces to string2. If the longer string1 determines the width of the MsgBox, wouldn't you only use half as many spaces
    to center string2? I tried that and it didn't look right. If string1 has 16 characters and string2 has 10, to even them up, wouldn't you add 3 spaces to the beginning of string2 and 3 spaces at the end? Sorry to be such a pain.
     
    CADmike, Aug 4, 2004
    #6
  7. CADmike

    Matt W Guest

    It sounds like you're trying to make more work for yourself.
    Why not just run with what you're given??

    --
    Matt W

    The difference between genius and stupidity is that genius has its limits.

    | Thanks, John. Your reply brings another question from me.
    | It would seem to me that I would use 1/2 of the value from subtracting the
    length of string2 from string1 when appending
    | spaces to string2. If the longer string1 determines the width of the
    MsgBox, wouldn't you only use half as many spaces
    | to center string2? I tried that and it didn't look right. If string1 has
    16 characters and string2 has 10, to even them up, wouldn't you add 3 spaces
    to the beginning of string2 and 3 spaces at the end? Sorry to be such a
    pain.
     
    Matt W, Aug 4, 2004
    #7
  8. ...but we all know that.

    =)

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Aug 4, 2004
    #8
  9. Yes, you're right about the spacing, but as was mentioned by Mr. Bell, your
    system is probably set to a proportional font, which means that different
    characters do not take up the same width.

    James
     
    James Belshan, Aug 4, 2004
    #9
  10. CADmike

    CADmike Guest

    Thanks to all of you who replied. Yes, I agree I'm making a mountain out of a mole hill. You guys have taught me something already. I just thought when you use vbCr, you could also set the justification, something like vbCrLeft or vbCrRight or vbCrCentered. As I now see, this is not an option. I will use what it gives me in the future.
     
    CADmike, Aug 4, 2004
    #10
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.