CryptoSys API Library Manual

Pre-dimensioning for VB

To create a string of, say, length 40 characters, do either:

Dim sData As String * 40

or

Dim sData As String
sData = String(40, " ")

If you know the output string needs to be the same size as the input, do this:

Dim strInput As String
Dim strOutput As String
strInput = "......"
strOutput = String(Len(strInput), " ")

To create a byte array of a given length:

Dim abData() As Byte
Dim nLen As Long
nLen = 40
ReDim abData(nLen - 1)

Note that byte arrays in VBA are indexed from 0 to nLen - 1, but an array dimensioned as abData(nLen - 1) actually has nLen elements.

To create a byte array of the same length as an existing array, do this:

Dim lpOutput() As Byte
ReDim lpOutput(Ubound(abInput))

To find the length of an existing byte array:

nLen = UBound(abData) - LBound(abData) + 1

Be careful, as this will cause a run-time error if abData() has not been ReDim'd. See the function cnvBytesLen in the VBA wrappers for a better and safer way to find the length.

[PREV: Using with Classic Visual Basic and VBA...]   [Contents]   [Index]   
   [NEXT: Zero-length byte arrays in VB6/VBA...]

Copyright © 2001-24 D.I. Management Services Pty Ltd. All rights reserved. Generated 2024-01-07T07:42:00Z.