Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Format string

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,1179
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Format string
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Format string - 7/25/2004 3:22:49 PM   
  LawfulEvil

 

Posts: 10
Score: 0
Joined: 7/25/2004
From:
Status: offline
how to add some leading zero into a string?

in VBA, i can use
mystr = format(123, "00000") 'return "00123"

how to do it in vbs?
 
 
Post #: 1
 
 Re: Format string - 7/26/2004 12:42:38 AM   
  mbouchard


Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
Mystr = "123"
mystr = "000" & mystr 'returns 000123

(in reply to LawfulEvil)
 
 
Post #: 2
 
 Re: Format string - 7/31/2004 9:39:42 PM   
  devguy

 

Posts: 15
Score: 0
Joined: 7/31/2004
From: USA
Status: offline
If you have variable length numbers you could also try something like...



Dim lNum
Dim sNum

lNum = 456
sNum = FormatNum(lNum, 6)
MsgBox sNum 'returns 000456

Function FormatNum (ByVal plNum, ByVal piDigits)
FormatNum = String(piDigits-Len(CStr(plNum)), "0") & CStr(plNum)
End Function

(in reply to LawfulEvil)
 
 
Post #: 3
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Format string Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts