Luciano Evaristo Guerche

A brazilian geek interested in .NET technologies

About Me

String.Format("My name is {0}", "Luciano Evaristo Guerche") (VB6)

A feature I loved in .NET (C# and VB.NET) is String.Format method. So I thought how I could have the same feature on VB6 and I came up with the following code.

Public Function StringDotFormat(ByVal strFormat As String, ByVal ParamArray aryPlaceHolders()) As String

Dim intPlaceHolderIndex As Integer

Dim strOutput As String

 

strOutput = strFormat

 

For intPlaceHolderIndex = LBound(aryPlaceHolders) To UBound(aryPlaceHolders)

strOutput = Replace(strOutput, "{" & intPlaceHolderIndex & "}", aryPlaceHolders(intPlaceHolderIndex))

Next

 

StringDotFormat = strOutput

End Function

 

Then used it the following way

Call StringDotFormat("My name is {0}", "Luciano Evaristo Guerche")

 

What do you think about it? Drop me a comment and let me know your opinion.

Comments

Andy Brudtkuhl said:

Why are you still using VB6?
# May 18, 2006 11:19 AM

A Guy said:

Who cares if somone is still using VB6. Does it really matter? Maybe they like VB6 and not .net. Seriously, I use VB6 because there's no real point to update. Mainly because only newer OS's can handle .net and older one's can't. Hence the Reason VB6 is better then .Net
# July 30, 2006 6:41 PM

DotNetter said:

Nice gadget, dude. Respect.

VB6 is powerful, but has become unwieldy and monolithic and because of its procedural roots is easy to abuse.  VB6's fun but not as powerful or cleanly OO as .net.

# May 15, 2008 6:35 AM

Ben said:

This is the most wonderful code snippit i've ever come across. Having to support legacy applications this code is immediately going into every project I touch.

You sir, are a guru.

# June 25, 2008 8:46 PM

Mike said:

I use VB6 because I write code for the Gov.  Currently the agency I am under contract to does not support dot Net.

Even though I am a .Net programmer I have to use VB6.

# August 25, 2008 1:55 AM

Todd said:

Thanks, this is exactly what I needed!

# September 29, 2008 3:25 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)