TextString Conversion Method?

Discussion in 'AutoCAD' started by Dan, Oct 5, 2004.

  1. Dan

    Dan Guest

    Hello Everyone,
    I wanted to ask what methods are better to use to carryout this function:

    I want to convert a textstrings in the following.
    EXAMPLES:
    ----------------------
    FROM: AB1204
    TO: 12'-4"

    FROM: AB0909
    TO: 9'-9"

    Basically, I have a 4 digit number representing feet and inches. I think I
    have figured a method out by "bullying" the textstring using IF, THEN, LEFT.
    RIGHT, and MID functions. IF/THEN for feet less than 10 feet, etc..

    I was thinking there must be a better way to do this.

    Any suggestions, code, example, etc. is grreatly appreciated. Throught this
    NewsGroup, I have learned much.

    Thank you,
    Dan
     
    Dan, Oct 5, 2004
    #1
  2. You're in luck... you don't need to bully the textstring's, the VAL function
    will take care of the values less than 10.... if your format is always
    4-digit, padded with zeroes (and always integers), you could just use:

    dim too as string, from as string
    from="AB1204"
    too = Format(Val(Mid(from, 3, 2))) & "'-" & Format(Val(Mid(from, 5, 2))) &
    """"
    msgbox too


    HTH,
    James
     
    James Belshan, Oct 5, 2004
    #2
  3. Dan

    Dan Guest

    AWESOME! I knew there must be a better way, and I learned about a new
    function.
    Thank you very much,
    Dan
     
    Dan, Oct 5, 2004
    #3
  4. Dan

    MP Guest

    Hi James,
    Curious about the use of val function
    I seem to get the same from
    too = Format(Mid(from, 3, 2)) & "'-" & Format(Mid(from, 5, 2)) & """"
    as from your line using val
    I didn't try every possible input value though
    It seems from the help description that it only eliminates alpha characters
    which in this case according to the specs is taken care of by the format of
    the input string
    ???
    tia
    Mark
     
    MP, Oct 5, 2004
    #4
  5. I'm old school... I'm used to the Format$() function, which required a
    numeric parameter. So you had to go from string "09" to number 9 to string
    "9". The Format() function can apparently take a number OR a string value.
    I didn't know it could do that.

    James
     
    James Belshan, Oct 5, 2004
    #5
  6. Dan

    MP Guest

    Thanks
    :)
    Mark
     
    MP, Oct 5, 2004
    #6
  7. NP... I think I still like the old school way, though. I'm not a big fan of
    Variants -- if I'm not even sure what type of variable I'm passing to a
    function, how likely is it that I know it has a valid value? An example....
    I was curious what would happen if I sent it a string that was semi-numeric,
    so I tried Format("5.45a") thinking I'd get an error or "5.45". The result
    was "5:45:00 AM". In hindsight, it makes sense, but how many other
    unexpected answers are there lurking out there?

    Just my opinion.....

    James
     
    James Belshan, Oct 5, 2004
    #7
  8. Dan

    Dan Guest

    Good questions. Thanks again. I learned alot.

    Dan
     
    Dan, Oct 6, 2004
    #8
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.