Visual Basic 6 function "zerofill"

Go back

Below you'll find the source for the Visual Basic 6 function zerofill.

Attribute VB_Name = "modZerofill"
' This function is downloaded from:
' You may freely distribute this file but please leave all comments, including this one, in it.
' @Author Stefan Thoolen <>

Option Explicit

' Completes a string by adding zero characters to the front
' @param    string  value       The input string
' @param    integer length      The length the return value must be
' @param    string  character   Optional, the character that should be used for filling, default: "0"
' @author   Stefan Thoolen <>
Public Function zerofill(ByVal value As String, ByVal length As Integer, Optional ByVal character = "0") As String
    If Len(value) >= length Then zerofill = value: Exit Function
    Dim i As Integer
        value = character & value
    Loop While Len(value) < length
    zerofill = value
End Function