Click or drag to resize

IMcOMGlobalMcSprintf Method

Performs a C-style sprintf to format a list of arguments into a string.

Namespace:  MediaCy.IQL.ObjectManager
Assembly:  MediaCy.IQL.ObjectManager (in MediaCy.IQL.ObjectManager.dll) Version: 10.0.6912.0
Syntax
VB
Function McSprintf ( 
	FormatString As String,
	<OutAttribute> ParamArray ByRef VariableNumberOfArguments As Object()
) As String

Parameters

FormatString
Type: SystemString
The formatting string can contain text and formatting escape sequences of the form %fn.nx, where f is optional flags, n.n is the width.precision and x is a formatting type. Use %s for strings, %d or %x (hexadecmal conversion) for all integral types (byte, short integer, integer or long integer). Use %f or %g for floating point types (either single precision float or double precision float). There is no formatting for currency or date types: you must convert these to a string and then use %s to place the string where you want it.
VariableNumberOfArguments
Type: SystemObject
An array of zero or more VARIANT arguments, each of which may be a scalar or array of any data type. The values may also be one of the built in user-defined-types (UDT): LONGPOINT, SINGLEPOINT or DOUBLEPOINT (and XXXXRECT or XXXXRANGE). You must explicitly break out the fields of your own defined UDT types. If an argument is an array or a UDT, the formatting string must contain a formatting escape sequence for each element of the array or each field of the UDT (see examples).

Return Value

Type: String
The converted string is returned.
Remarks
McSprintf allows you to convert an arbitrary number of arguments of virtually any string or numeric type into text under the control of a C-style sprinf formatting string. When converting arrays to text, consider using McToText instead of McSprintf. McToText can deal with arrays of arbitrary length and allows you to specify a formatting string for text before, between and after the array, each value and each row of a mult-dimensionall array. The McSprintf method does not recognize C-style, '\', escape sequences in either its FormatString or any strings included as arguments. However, as shown in the examples, you can use the McCStr method to convert C-style escape sequences. The number of arguments is limited to about 100 and the output string is limited to about 8000 characters. Excessive arguments are ignored and output is truncated at the character limit, both without error.
Examples
VB
Debug.Print McSprintf(McCStr("\nThis is a test with one string arg. %s"), "Hello world") & vbCrLf & _
"  Above was McSprintf(McCStr(""This is a test with one string arg. %s""), ""Hello world"")"
Debug.Print McSprintf(McCStr("\nTest of mixed scalar args: Byte(%d), Short(%d), Long(%d), Float(%f), Double(%f)"), _
CByte(10), CInt(10), CLng(10), CSng(10), CDbl(10)) & vbCrLf & _
"  Above was McSprintf(McCStr(""Test of mixed scalar args: Byte(%d), Short(%d), Long(%d), Float(%f), Double(%f)""), CByte(10), CInt(10), CLng(10), CSng(10), CDbl(10))"
Debug.Print McSprintf(McCStr("\nThe %s %c is Chr(%d), %s"), "letter", 65, 65, "right?") & vbCrLf & _
"  Above was McSprintf(McCStr(""\nThe %s %c is Chr(%d), %s""), ""letter"", 65, 65, ""right?"")"
Debug.Print McSprintf(McCStr("\nThis is a string with no arguments.")) & vbCrLf & _
"  Above was McSprintf(McCStr(""\nThis is a string with no arguments.""))"
Dim myPt As LONGPOINT
myPt.x = 10
myPt.y = 20
Debug.Print McSprintf(McCStr("\nHere is a LONGPOINT: x=%d, y=%d."), myPt) & vbCrLf & _
"  Above was McSprintf(McCStr(""\nHere is a LONGPOINT: x=%d, y=%d.""), myPt)"
Dim mcobjString As McObject
Set mcobjString = McObjectTemp("string in an McObject")
Debug.Print McSprintf(McCStr("\nCan we show a %s?"), mcobjString) & vbCrLf & _
"  Above was McSprintf(McCStr(""\nCan we show a %s?""), mcobjString)"
Dim strArray(0 To 2) As String
strArray(0) = "Line 0."
strArray(1) = "Line 1."
strArray(2) = "Line 2."
Debug.Print McSprintf(McCStr("\nAn array of strings.\n1. %s\n2. %s\n3. %s"), strArray) & vbCrLf & _
"  Above was McSprintf(McCStr(""\nAn array of strings.\n1. %s\n2. %s\n3. %s""), strArray)"
'Convert the above array of strings above to an McObject, and then sprintf that
Dim mcobjStrArray As McObject
Set mcobjStrArray = McObjectTemp(strArray)
Debug.Print McSprintf(McCStr("\nAn array of strings in an McObject\n1. %s\n2. %s\n3. %s"), mcobjStrArray) & vbCrLf & _
"  Above was McSprintf(McCStr(""\n\nAn array of strings in an McObject\n1. %s\n2. %s\n3. %s""), mcobjStrArray)"
'**** The output produced by the above tests is shown below ****
'
' This is a test with one string arg. Hello world
'   Above was McSprintf(McCStr("This is a test with one string arg. %s"), "Hello world")
'
' Test of mixed scalar args: Byte(10), Short(10), Long(10), Float(10.000000), Double(10.000000)
'   Above was McSprintf(McCStr("Test of mixed scalar args: Byte(%d), Short(%d), Long(%d), Float(%f), Double(%f)"), CByte(10), CInt(10), CLng(10), CSng(10), CDbl(10))
'
' The letter A is Chr(65), right?
'   Above was McSprintf(McCStr("\nThe %s %c is Chr(%d), %s"), "letter", 65, 65, "right?")
'
' This is a string with no arguments.
'   Above was McSprintf(McCStr("\nThis is a string with no arguments."))
'
' Here is a LONGPOINT: x=10, y=20.
'   Above was McSprintf(McCStr("\nHere is a LONGPOINT: x=%d, y=%d."), myPt)
'
' Can we show a string in an McObject?
'   Above was McSprintf(McCStr("\nCan we show a %s?"), mcobjString)
'
' An array of strings.
' 1. Line 0.
' 2. Line 1.
' 3. Line 2.
'   Above was McSprintf(McCStr("\nAn array of strings.\n1. %s\n2. %s\n3. %s"), strArray)
'
' An array of strings in an McObject
' 1. Line 0.
' 2. Line 1.
' 3. Line 2.
'   Above was McSprintf(McCStr("\n\nAn array of strings in an McObject\n1. %s\n2. %s\n3. %s"), mcobjStrArray)
See Also