[AccessD] Count the occurrences of each character in a string

Stuart McLachlan stuart at lexacorp.com.pg
Wed Sep 7 07:44:17 CDT 2022


Yep, it's my go-to for a load of utility applications.  It is a 32bit compiler so doesn't produce 
64 bit applications, but it can use the complete win32API so apart from the 32bit limits of 
around 2GB of usable memory and a 4GB address range, there is little that it won't do and it 
produces very small, fast applications with no external dependencies.  Basically, anything 
you can do in C, you can do far more easily in PB.

Take a look in your "C:\Program file (x86)" directory. Every application you see there is also 
32bit :).

You can use it to create standard 32bit DLLs that will work with any  32 bit application ( just 
like all the DLLs that are in your Windows\SysWOW64 directory  :)

Static Link Libraries (SLLs) are essential pre-compiled libraries than can be easily inserted 
into anPB application.  We generally use them for precompiled, thouroughly tested and 
debugged functions to save re-inventing the wheel and for distributing copyright 
development tools to other PB developers. (All of my PB applications that use OBDC work 
with a SLL library I purchased - SQLTools. It allows me to  build and distribute a single 
executable file rather than an exe and a number of DLLS.


On 7 Sep 2022 at 6:59, Arthur Fuller wrote:

> Thanks, Stuart.
> 
> Changing subject a bit, you caused me to look up PowerBasic, and I
> noticed that it is 32-bit, with a mention that it is compatible with
> 64-bit Windows. How does that work, regarding DLLs? Is that the reason
> it also create Static Link Libraries? Sorry, I haven't had time to
> read that far in the docs, which I downloaded to see what's what. It
> looks like an excellent product, and the price is right, too.
> 
> On Wed, Sep 7, 2022 at 6:41 AM Stuart McLachlan
> <stuart at lexacorp.com.pg> wrote:
> 
> > Sorry. PB = PowerBASIC. I re-wrote the VBA to use with my PowerBASIC
> > compiler.
> >
> > It's just a minor modification  which  replaces the  very similar
> > block in the original post. ie. the function will be as follows. 
> > (It's just the insertion of an IF...Then construct around the "y"
> > loop.)
> >
> > Function Lettercount(sInputString As String, CaseSensitive As
> > Boolean) As Long
> >     Dim lStr As Long, x As Long, y As Long, compare As Long
> >     Dim sTxt As String
> >     Dim freq() As Long
> >
> >     'Initialise
> >     sTxt = sInputString 'we are going to modify the string!
> >     If CaseSensitive = True Then
> >         compare = vbBinaryCompare
> >     Else
> >         compare = vbTextCompare
> >     End If
> >     lStr = Len(sTxt)
> >     ReDim freq(1 To lStr)
> >
> >     'Get the letter counts
> >     For x = 1 To lStr
> >        If Asc(Mid$(sTxt, x, 1)) <> 0 Then ' skip over the "y" loop
> >        if
> > character is already zeroed
> >            freq(x) = 1
> >            For y = x + 1 To lStr
> >                If StrComp(Mid$(sTxt, x, 1), Mid$(sTxt, y, 1),
> >                compare) = 0
> > Then
> >                    freq(x) = freq(x) + 1
> >                    Mid$(sTxt, y, 1) = Chr$(0)
> >               End If
> >            Next
> >       End If        ' End of skipping over the "y" loop
> >    Next
> >
> >   'Display the results
> >    For x = 1 To lStr
> >       If Mid$(sTxt, x, 1) <> Chr$(0) Then
> >         Debug.Print Mid$(sTxt, x, 1) & "  -  " & str$(freq(x))
> >       End If
> >    Next
> > End Function
> >
> >
> > On 7 Sep 2022 at 5:56, Arthur Fuller wrote:
> >
> > > Hi Stuart,
> > >
> > > I don't know what a PB function is. Also, I'm not sure where to
> > > place this new code.
> > >
> > > On Wed, Sep 7, 2022 at 3:13 AM Stuart McLachlan
> > > <stuart at lexacorp.com.pg> wrote:
> > >
> > > > Just converted this to a PB function and in doing so, I realised
> > > > that it was slower than necessary. With a large string you will
> > > > save a LOT of iterations with
> > > >
> > > > For x = 1 To lStr
> > > >        If Asc(Mid$(sTxt, x, 1)) <> 0 Then
> > > >             freq(x) = 1
> > > >             For y = x + 1 To lStr
> > > >                 If StrComp(Mid$(sTxt, x, 1), Mid$(sTxt, y, 1),
> > > >                 compare) =
> > > > 0 Then
> > > >                     freq(x) = freq(x) + 1
> > > >                     Mid$(sTxt, y, 1) = Chr$(0)
> > > >                End If
> > > >             Next
> > > >        End If
> > > > Next
> > > >
> >
> > --
> > AccessD mailing list
> > AccessD at databaseadvisors.com
> > https://databaseadvisors.com/mailman/listinfo/accessd
> > Website: http://www.databaseadvisors.com
> >
> 
> 
> -- 
> Arthur
> -- 
> AccessD mailing list
> AccessD at databaseadvisors.com
> https://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
> 




More information about the AccessD mailing list