Signature (Visual Basic / VBA)
Public Function FileCharacterFrequency( _
ByRef rCounts() As Variant _
, ByVal vFileName As Variant _
) As Long
Code Example
Assuming
StringToFile(Chr$(1) + Chr$(2) + Chr$(1), "FCF.TMP") = True
for example
FileCharacterFrequency(avarCounts(), "FCF.TMP") = 3
Dim avarCounts() As Variant
leaves
LBound(avarCounts) = 0
UBound(avarCounts) = 255
avarCounts(0) = 0&
avarCounts(1) = 2&
avarCounts(2) = 1&
avarCounts(3) = 0&
' ...
avarCounts(255) = 0&
Parameters
| Parameter | Description |
|---|---|
| rCounts | Dynamic array of Variant values that will receive the character counts. This function will automatically re-dimension the array from 0 to 255. The value of element N is the count of characters with that ASCII value. |
| vFileName | Name of the file whose character frequency is to be determined. Function returns -1 if vFileName is Null or cannot be fixed-up to a String. |
Return Value
Function returns the total number of characters read (the size of the file) upon success. Function returns -1 upon failure, such as when the file does not exist or cannot be read.
Notes & Version History
| v1.2 BugFix | Corrected a problem so that elements will now be set to 0& (zero Long) instead of left as Empty when the corresponding character does not appear in the file. |