Lbs with null value in vbscript

I am trying to put a line with 0 to the left. The output string should be 7. Here is my code:

inputstr = "38" in = string(7 - Len(inputStr),0) & inputStr msgbox in 

I get an error. Expected expression. Please help me. Thank you.

+7
vbscript
source share
3 answers

The following code will work 5% faster:

 inputStr = "38" result = Right("0000000" & inputStr, 7) msgbox result 
+11
source share

This function will leave an input value for a given number of characters using a given fill character, without reducing the input value:

 Function LPad(s, l, c) Dim n : n = 0 If l > Len(s) Then n = l - Len(s) LPad = String(n, c) & s End Function 

Output:

 >>> WScript.Echo LPad(12345, 7, "0") 0012345 >>> WScript.Echo LPad(12345, 3, "0") 12345 
+10
source share

in is a reserved word, therefore it cannot be used as a variable name, and you must pass the string "0" not an integer 0 , therefore:

 inputStr = "38" result = string(7 - Len(inputStr), "0") & inputStr msgbox result 
+5
source share

All Articles