printf for VB6 Author: Dave Date: 09.21.13 - 2:01am
Here is a basic printf implementation for VB6.
If you use it in any serious code make sure to beef up
the type checks and add error handling. It is a nicer way to
build up complex strings without all those verbose and complicated ampersands, quotes and inline calls to hex(), ucase(), chr() etc.
Not shown below, but it also supports \t \r \n %%
Example:
List1.AddItem printf("number 0x%x", 16)
List1.AddItem printf("number %08x", &HCC)
List1.AddItem printf("number %8X", &HCC)
List1.AddItem printf("this is %s and can also be %S", "my string", "upper case")
List1.AddItem printf("%s", "string with no prefix")
List1.AddItem printf("0xCC in decimal = %d", &HCC)
List1.AddItem printf("chr(&h41) = %c", &H41)
List1.AddItem printf("chr(&h41) = %c it is my %s", &H41, "favorite letter")
Output:
number 0x10
number 000000CC
number CC
this is my string and can also be UPPER CASE
string with no prefix
0xCC in decimal = 204
chr(&h41) = A
chr(&h41) = A it is my favorite letter
Comments: (0)
|