Results 1 to 7 of 7

Thread: VB6 - String Formatting

  1. #1

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    VB6 - String Formatting

    There is this bit of code:
    Code:
    Format(UCase(value), "!@@@@@@@@@@@@@@@@")
    Looking at the user-defined string formats documentation, I wanted to verify that this code is doing the following:
    1. Force the incoming string to uppercase
    2. Take the last 16 characters
    3. If the length of the string is less than 16, append spaces for each missing character
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: VB6 - String Formatting

    If it were me I would just try it and see, likely be quicker than waiting on a response.

  3. #3

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: VB6 - String Formatting

    I didn't think that it was pertinent to my thread, but just to clarify, I did run the code in the immediate window using several different strings as the value. Those tests, along with the referenced documentation, was how I determined what I think the code is doing.

    I asked the question here to make sure that I'm not missing anything because I'm not terribly familiar with those format symbols and I wanted verify what the specific piece of code was doing.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  4. #4
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,663

    Re: VB6 - String Formatting

    Just Do:


    Code:
    value =  ucase$(left$(value & space(16, "@"),16))
    1. Always Fill a 16 byte buffer,
    2. Append your actual value to it
    3. return the 16 left characters
    4. make it all Uppercase
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  5. #5

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: VB6 - String Formatting

    @some1uk03 - to give you some background, I'm rewriting a VB6 application. So I don't need an alternative to the code provided in my original post, but rather confirmation that what I outlined in my numbered list accurately represents the code.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  6. #6
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: VB6 - String Formatting

    Quote Originally Posted by dday9 View Post
    There is this bit of code:
    Code:
    Format(UCase(value), "!@@@@@@@@@@@@@@@@")
    Looking at the user-defined string formats documentation, I wanted to verify that this code is doing the following:
    1. Force the incoming string to uppercase
    2. Take the last 16 characters
    3. If the length of the string is less than 16, append spaces for each missing character
    https://docs.microsoft.com/en-us/off...r-applications


    That should be right. UCase definately will upper case the string, and that's done first. The bang forces left-to-right fill... and the @ is a character placeholder. It will display a space if the string is short... but I'm not 100% sure it will truncate. I know that when formatting numbers, it will overflow... not sure what it does with stirngs... may need to experiment with it... or for safe measure toss in a Left$() around that whole bugger and take the left 16.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 - String Formatting

    Code:
        Debug.Print "["; Format$(UCase$("aAAa"), "!@@@@@@@@@@@@@@@@"); "]"
        Debug.Print "["; Format$(UCase$("aAAa.......bbBBbbcdefghijklmnopq"), "!@@@@@@@@@@@@@@@@"); "]"
    Code:
    [AAAA            ]
    [BCDEFGHIJKLMNOPQ]
    Don't use the Variant form of UCase$(), it is only there for VBScript compatibility.


    Also:

    Code:
        Debug.Print "["; Format$("aAAa", ">!@@@@@@@@@@@@@@@@"); "]"
        Debug.Print "["; Format$("aAAa.......bbBBbbcdefghijklmnopq", ">!@@@@@@@@@@@@@@@@"); "]"
    Code:
    [AAAA            ]
    [BCDEFGHIJKLMNOPQ]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width