Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

PrintF - Transforming template strings
[ All Languages » VB »  String]

Total Hit ( 1794)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 



Click here to copy the following block
' This VB6 function returns a string with a set of parameters replaced with
' variables, similar to the C function printf().

Public Function PrintF(strMask As String, ParamArray Values()) As String
  On Error Resume Next
  ' pass in a mask with variables in the order of \0, \1, \2, etc
  ' if they are found, replace with the corresponding values()
  Dim lngNbrValues As Long, lngCount As Long
  Dim strX As String, strFind As String
  
  lngNbrValues = UBound(Values)
  
  ' first, find any \\, \t or \n and replace those  
  strX = Replace(strMask, "\\", "¥¥¥")
  strX = Replace(strX, "\t", vbTab)
  strX = Replace(strX, "\n", vbNewLine)
  
  ' next, loop backward through the values, looking
  ' for each item in turn. If it's found, replace it
  For lngCount = lngNbrValues To 0 Step -1
    strFind = "\{" + CStr(lngCount) + "}"
    strX = Replace(strX, strFind, Values(lngCount))
    
    strFind = "\" + CStr(lngCount)
    strX = Replace(strX, strFind, Values(lngCount))
  Next lngCount

  strX = Replace(strX, "¥¥¥", "\")
  PrintF = strX
  On Error GoTo 0  
End Function

' And here's some code to test the function :

Public Function GenerateNewFilename(strFilename As String) As String
  Dim strNew As String
  Dim dteNow As Date
  
  dteNow = Now()

  strNew = PrintF("_\0\1\2_\3\4\5_" + strFilename, Format(CStr(Year(dteNow)), _
    "0000"), Format(CStr(Month(dteNow)), "00"), Format(CStr(Day(dteNow)), _
    "00"), Format(CStr(Hour(dteNow)), "00"), Format(CStr(Minute(dteNow)), _
    "00"), Format(CStr(Second(dteNow)), "00"))
 
  GenerateNewFilename = strNew
End Function

' Note: in VB.NET, the String.Format provides much more than this,
' as it allows to specify how to format the values that replace the
' placeholders.


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.