-
Oct 1st, 2020, 01:47 PM
#1
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:
- Force the incoming string to uppercase
- Take the last 16 characters
- If the length of the string is less than 16, append spaces for each missing character
-
Oct 1st, 2020, 02:22 PM
#2
Re: VB6 - String Formatting
If it were me I would just try it and see, likely be quicker than waiting on a response.
-
Oct 1st, 2020, 02:32 PM
#3
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.
-
Oct 1st, 2020, 02:34 PM
#4
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.
-
Oct 1st, 2020, 02:37 PM
#5
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.
-
Oct 1st, 2020, 04:06 PM
#6
Re: VB6 - String Formatting
Originally Posted by dday9
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:
- Force the incoming string to uppercase
- Take the last 16 characters
- 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
-
Oct 1st, 2020, 08:09 PM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|