Typical codings discussed in the previous post
Here are just two sample codings from the workbook.
The first coding uses the straight AASI version of the StrTrimA( , ) , and tries trimming nothing from as single character, or rather it loops through the entire ChW(x) list of characters , x = 0 - 65535 , attempting to trim nothing from it. The results it presents in column K https://i.postimg.cc/m2GW2cCN/Str-Tr...n-column-K.jpg
Coding is in file the worksheets object code module, StrTrimRedundantSSD2
Code:
Option Explicit
' https://learn.microsoft.com/en-us/windows/win32/api/shlwapi/nf-shlwapi-strtrima
Private Declare Function StrTrim Lib "shlwapi.dll" Alias "StrTrimA" (ByVal psz As String, ByVal pszTrimChars As String) As Long ' ' Straight AASI - we'll be passing vb string to api
Private Declare Function StrTrimTrickAW Lib "shlwapi.dll" Alias "StrTrimA" (ByVal psz As Long, ByVal pszTrimChars As Long) As Long ' Trick _ Half way house - we'll be passing the StrPtr to API
' https://learn.microsoft.com/en-us/windows/win32/api/shlwapi/nf-shlwapi-strtrimw
Private Declare Function StrTrimTrickW Lib "shlwapi.dll" Alias "StrTrimW" (ByVal psz As Long, ByVal pszTrimChars As Long) As Long ' Full Unicorn's Bollox - we'll be passing the StrPtr to API
Private Declare Function StrTrimTrickWUA Lib "shlwapi.dll" Alias "StrTrimW" (ByVal psz As String, ByVal pszTrimChars As String) As Long ' we'll be passing vb string to api
' https://eileenslounge.com/viewtopic.php?p=324039#p324039
Private Sub JimmyRiddleAChrW() ' Straight AASI ChrW
Rem 0
Dim Ay As String, Bea As String, Boo As Boolean, Cwt As Long, BooToo As Boolean
For Cwt = 0 To 65535 ' All ChW(x) list of characters , x = 0 - 65535
Let Ay = ChrW(Cwt): Let Bea = Ay ' Bea will be used later to comparte with what Ay becomes after used
Rem 1
Debug.Print " " & Cwt & " " & ChrW(Cwt) & " "; ' Some immediate Window output - genrally less useful in such experiments as the VB Editor and Immediate window do not do WUnicode so that adds another confusion. I ust the Excel Spreadsheet instead for viewable output --###
Rem 2 ' call an AASI ' API function that does nothing to a character
Let Boo = StrTrim(Ay, "") ' ' The typical returned value from a function does not give a typical direct result. In this case it tells us if anything was trimmed. We do not need this result
Debug.Print Ay = Bea; ' Some immediate Window output
Let BooToo = Ay = Bea ' The original variable Ay now has possibly overwritten in it a new value, or not. Investigating this is one of the purposes of this coding
Let Range("K" & Cwt + 3 & "") = " " & Bea & " " & BooToo & " " & Ay ' I use the Excel Spreadsheet for output as it appears to have no issues with reproducing accurately many thousands of different characters. -------------------------------------------------------------###
Next Cwt
End Sub
(The Immediate window results are of limited use in such experiments as the VB Editor and Immediate window do not do WUnicode so that adds another confusion. In further experiments we will mostly ignore the Immediate window or any other typical VB Editor debugging tools )
https://i.postimg.cc/m2GW2cCN/Str-Tr...n-column-K.jpg

The second coding example is the corresponding straight AASI approach with the attempt to get the StrTrim to actually do a trim
I give it 4 characters, for example
baba or caca
, trimming correspondingly for those two examples with
b or c
, using arbitrarily the character a as a filler. So in those example the results would be expected of
aba or aca
Coding is in worksheets object code module StrTrimDoingSSD2
Code:
Option Explicit
' https://learn.microsoft.com/en-us/windows/win32/api/shlwapi/nf-shlwapi-strtrima
Private Declare Function StrTrim Lib "shlwapi.dll" Alias "StrTrimA" (ByVal psz As String, ByVal pszTrimChars As String) As Long ' ' Straight AASI - we'll be passing vb string to api
Private Declare Function StrTrim Lib "shlwapi.dll" Alias "StrTrimA" (ByVal psz As String, ByVal pszTrimChars As String) As Long ' ' Straight AASI - we'll be passing vb string to api
Private Declare Function StrTrimTrickAW Lib "shlwapi.dll" Alias "StrTrimA" (ByVal psz As Long, ByVal pszTrimChars As Long) As Long ' Trick _ Half way house - we'll be passing the StrPtr to API
' https://learn.microsoft.com/en-us/windows/win32/api/shlwapi/nf-shlwapi-strtrimw
Private Declare Function StrTrimTrickW Lib "shlwapi.dll" Alias "StrTrimW" (ByVal psz As Long, ByVal pszTrimChars As Long) As Long ' Full Unicorn's Bollox - we'll be passing the StrPtr to API
Private Declare Function StrTrimTrickWUA Lib "shlwapi.dll" Alias "StrTrimW" (ByVal psz As String, ByVal pszTrimChars As String) As Long ' we'll be passing vb string to api
' https://eileenslounge.com/viewtopic.php?p=324039#p324039
Private Sub JimmyRiddleAChrW() ' Straight AASI ChrW
Rem 0
Dim Ay As String, Bea As String, Boo As Boolean, Cwt As Long, BooToo As Boolean
For Cwt = 0 To 65535
Let Ay = ChrW(Cwt) & "a" & ChrW(Cwt) & "a": Let Bea = Ay ' Bea will be used later to comparte with what Ay becomes after used. Ay will itself possibly change on "it's journey through" the StrTrim function
Rem 1
Rem 2 ' call an AASI ' API function that does, or is intended to do, something to a string
Let Boo = StrTrim(Ay, ChrW(Cwt)) ' ' The typical returned value from a function does not give a typical direct result. In this case it tells us if anything was trimmed. We do not need this result, although we will check it sometimes to see if it matches the apparant results
Let BooToo = Right(Bea, 3) = Left(Ay, 3) ' If the function has done as intended, which is to trim of the ChrW(Cwt) then we expect the three right most characters on the original 4 character string to look like the returned results, which are overwritten into the original variable, Ay , (but there is a subtlty as we may expect an invisible Chr(0) on the end of the output, so we only compare to the first 3
Let Range("K" & Cwt + 3 & "") = " " & Bea & " " & BooToo & " " & Ay ' & " " & Len(Ay) & " " & Boo ' ' I use the Excel Spreadsheet for output as it appears to have no issues with reproducing accurately many thousands of different characters.
Next Cwt
End Sub
Private Sub JimmyRiddleAChr() ' Straight AASI Chr
https://i.postimg.cc/SKJmDYf9/First-...-something.jpg
Bookmarks