VB6Parse / Library / String / lenb

VB6 Library Reference

LenB Function

The LenB function returns a Long containing the number of bytes used to represent a string in memory. This function operates on byte count rather than character count, which is important when working with ANSI strings, DBCS (Double-Byte Character Set), or when you need to know the actual memory footprint of a string.

Syntax

LenB(string | varname)

Parameters

Return Value

Returns a Long specifying the number of bytes required to store the string or variable in memory.

Behavior

Difference from Len

The LenB function returns the byte count, while the Len function returns the character count. For single-byte character sets, they are identical. For Unicode (VB6's default string type), LenB will return twice the value of Len.

Examples

' Get byte length of a string
Dim size As Long
size = LenB("Hello")  ' Returns 10 (5 characters * 2 bytes each in Unicode)

' Compare with character length
Dim charLen As Long
Dim byteLen As Long
charLen = Len("Test")   ' Returns 4
byteLen = LenB("Test")  ' Returns 8 (Unicode)

' Check memory size
Dim buffer As String
buffer = Space$(100)
Dim bufferSize As Long
bufferSize = LenB(buffer)  ' Returns 200 bytes

← Back to String | View all functions