<-- Previous || Up || Next -->

File Character Frequency Function
File Operations Class

Public Function FileCharacterFrequency( _
      ByRef rCounts() As Variant _
    , ByVal vFileName As Variant _
    ) As Long

Count the frequency of each character within a file.
Character counts are returned in a one-dimensional array of Variant values.

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&
See also:
    CharacterCountsToVariantVector Function
    SortCharactersByFrequency Function
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.

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.

Copyright 1996-1999 Entisoft
Entisoft Tools is a trademark of Entisoft.