Page 11 of 11 FirstFirst ... 91011
Results 101 to 110 of 110

Thread: Notes tests, string, manipulation of text files and string manipulations

  1. #101
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,466
    Rep Power
    10
    Some notes to go with this forum post
    https://eileenslounge.com/viewtopic....314200#p314200
    https://eileenslounge.com/viewtopic....314281#p314281




    Just for fun, the way I might do it.
    Same test data, just to help compare offered solutions:
    https://i.postimg.cc/NjzZxy0C/Test-d...n-column-D.jpg
    Test data 5 rows of columns A - C to be summed in column D.jpg

    I want in column D the summed values and also the numbers used in the summation , - I want the numbers used in the summation, for example, for future reference even if I delete columns A - Z

    I would do this ..
    Code:
    Sub My2Euros() '  https://www.excelfox.com/forum/showthread.php/2860-Notes-tests-string-manipulation-of-text-files-and-string-manipulations?p=23991&viewfull=1#post23991
     Let Selection = "=A1+B1+C1 & ""                     "" & A1 & "" "" & B1 & "" "" & C1"   '     This line is like putting this formula in cell D1    =A1+B1+C1 & "          " & A1 & " " & B1 & " " & C1         and dragging it down
     Let Selection = Selection.Value                                                          '     line changes the cell values to the value the formula gives, rather than the formula, ( this is necessary so that I can still everything as I initially do in the sum result column, even if I delete the columns A - C
    End Sub
    The first code line is like putting this formula in cell D1
    Code:
    =A1+B1+C1 & "                     " & A1 & " " & B1 & " " & C1
    https://i.postimg.cc/wjvSJ59s/First-...1-A1-B1-C1.jpg
    First code line is like this in D1 A1+B1+C1 & & A1 & & B1 & &.jpg
    , and then dragging it down.

    The second code line changes the cell values to the value the formula gives, rather than the formula, ( this is necessary so that I can still everything as I initially do in the sum result column, even if I delete the columns A - C


    That way is just my preference for a few reasons:
    _ Text and text storage in computers is, as I understand it as a computer Layman, cheap and easy these days, so having a lot of text anywhere idoes no noticeable harm or performance degradation
    _ I would probably have things in the next column and my columns are not usually very wide., so I usually only see the results clearly, but if need be, to get full information ,I can extend the column , look in the formula bar or copy cells or a cell, etc.
    https://i.postimg.cc/TPW36LNB/Extend...-full-info.jpg
    Extended column or look in formula bar for full info.jpg
    Last edited by DocAElstein; 02-15-2024 at 11:21 PM.
    Seasonal greetings :-)

  2. #102
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,466
    Rep Power
    10
    Some notes to go with this forum post
    https://eileenslounge.com/viewtopic....314200#p314200
    https://eileenslounge.com/viewtopic....314281#p314281




    Just for fun, the way I might do it.
    Same test data, just to help compare offered solutions:
    https://i.postimg.cc/NjzZxy0C/Test-d...n-column-D.jpg
    Test data 5 rows of columns A - C to be summed in column D.jpg

    I want in column D the summed values and also the numbers used in the summation , - I want the numbers used in the summation, for example, for future reference even if I delete columns A - Z

    I would do this ..
    Code:
    Sub My2Euros() '  https://www.excelfox.com/forum/showthread.php/2860-Notes-tests-string-manipulation-of-text-files-and-string-manipulations?p=23991&viewfull=1#post23991
     Let Selection = "=A1+B1+C1 & ""                     "" & A1 & "" "" & B1 & "" "" & C1"   '     This line is like putting this formula in cell D1    =A1+B1+C1 & "          " & A1 & " " & B1 & " " & C1         and dragging it down
     Let Selection = Selection.Value                                                          '     line changes the cell values to the value the formula gives, rather than the formula, ( this is necessary so that I can still everything as I initially do in the sum result column, even if I delete the columns A - C
    End Sub
    The first code line is like putting this formula in cell D1
    Code:
    =A1+B1+C1 & "                     " & A1 & " " & B1 & " " & C1
    https://i.postimg.cc/wjvSJ59s/First-...1-A1-B1-C1.jpg
    First code line is like this in D1 A1+B1+C1 & & A1 & & B1 & &.jpg
    , and then dragging it down.

    The second code line changes the cell values to the value the formula gives, rather than the formula, ( this is necessary so that I can still everything as I initially do in the sum result column, even if I delete the columns A - C


    That way is just my preference for a few reasons:
    _ Text and text storage in computers is, as I understand it as a computer Layman, cheap and easy these days, so having a lot of text anywhere idoes no noticeable harm or performance degradation
    _ I would probably have things in the next column and my columns are not usually very wide., so I usually only see the results clearly, but if need be, to get full information ,I can extend the column , look in the formula bar or copy cells or a cell, etc.
    https://i.postimg.cc/TPW36LNB/Extend...-full-info.jpg
    Extended column or look in formula bar for full info.jpg
    Seasonal greetings :-)

  3. #103
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,466
    Rep Power
    10
    Some extended notes for this main forum post
    https://eileenslounge.com/viewtopic....a7d27b#p315620
    https://eileenslounge.com/viewtopic.php?p=315620&sid=922f8eb190547f727ca48c954aa7d27b#p315620
    This is post
    https://www.excelfox.com/forum/showt...ll=1#post24092
    https://www.excelfox.com/forum/showthread.php/2860-Notes-tests-string-manipulation-of-text-files-and-string-manipulations?p=24092&viewfull=1#post24092







    This particular post is intended just to reproduce , for later clarity , some things in the original main forum post

    At this point in the proceedings I had got to approximately these posts, or thereabouts . https://eileenslounge.com/viewtopic....315596#p315596
    https://eileenslounge.com/viewtopic....315512#p315512
    and the coding I was using was in **essence this following, ( ** changed just slightly to make comparisons with the next two post , ( https://www.excelfox.com/forum/showt...ll=1#post24094 https://www.excelfox.com/forum/showt...ll=1#post24093 ) , easier

    Those last two Eileen’s Lounge links, https://eileenslounge.com/viewtopic....315596#p315596
    https://eileenslounge.com/viewtopic....315512#p315512
    , sum up well what I was doing and this coding version of mine is a good summary of a shortened version of my main coding ideas, ( I have farmed out the BB Code tag making part to another routine, as that is not the main point of the current discussions. The main point of the current discussions is the getting of the appropriate URL to match a highlight key word in Microsoft Word)

    Code:
    Sub BBCodeTagsURL_()  '     https://eileenslounge.com/viewtopic.php?p=315503#p315503  https://www.excelfox.com/forum/showthread.php/2860-Notes-tests-string-manipulation-of-text-files-and-string-manipulations?p=24092&viewfull=1#post24092
    Rem 0  The text you selected
    Dim SelTxt As String
     Let SelTxt = Selection.Text ' A text I highlighted in Word
    
    Rem 1 Some groups of   name, URL,   pairs
    Dim strItAll As String, strEileen As String, strFox As String
     Let strEileen = "Eileen's Lounge, https://eileenslounge.com/app.php/portal, eileenslounge, https://eileenslounge.com/app.php/portal, The Windows Clipboard, https://www.eileenslounge.com/viewtopic.php?p=300947#p300947, "
     Let strFox = "Excel Fox, https://www.excelfox.com/forum/forum.php, excelfox, https://www.excelfox.com/forum/forum.php, "
     
     Let strItAll = strEileen & strFox
    
    Rem 2 Find the URL if there is one
    Dim strURL As String
            If InStr(1, strItAll, SelTxt, vbTextCompare) > 0 Then
         Let strURL = Mid(strItAll, InStr(InStr(1, strItAll, SelTxt, vbTextCompare), strItAll, "http", vbBinaryCompare), InStr(InStr(InStr(1, strItAll, SelTxt, vbTextCompare), strItAll, "http", vbBinaryCompare), strItAll, ",", vbBinaryCompare) - InStr(InStr(1, strItAll, SelTxt, vbTextCompare), strItAll, "http", vbBinaryCompare))
        Else
         Let strURL = ""
        End If
    
    Rem 3 Make the BB Code Tag URL thing
    Call MakeABBCodeTagURL(strURL)
    
    End Sub
    Sub MakeABBCodeTagURL(ByVal strURL As String) ' https://www.excelfox.com/forum/showthread.php/2860-Notes-tests-string-manipulation-of-text-files-and-string-manipulations?p=24092&viewfull=1#post24092
        With Selection
         .Text = "[URL=" & strURL & "] " & .Text & " [/url]"
         .Collapse Direction:=wdCollapseEnd
         .Font.Color = wdColorAutomatic
        End With
    End Sub
    Last edited by DocAElstein; 03-27-2024 at 10:52 PM.

  4. #104
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,466
    Rep Power
    10
    Some extended notes for this main forum post
    https://eileenslounge.com/viewtopic....a7d27b#p315620
    https://eileenslounge.com/viewtopic.php?p=315620&sid=922f8eb190547f727ca48c954aa7d27b#p315620
    This is post
    https://www.excelfox.com/forum/showt...l=1#post240923
    https://www.excelfox.com/forum/showthread.php/2860-Notes-tests-string-manipulation-of-text-files-and-string-manipulations?p=24093&viewfull=1#post24093








    snb's offerings, for Word VBA / VBA alternative for App Match of Excel VBA


    Code:
    'Option Explicit
    Sub M_snb() ' https://eileenslounge.com/viewtopic.php?f=26&t=40789&p=315620#p315620
       c00 = "aa bb cc dd ee ff gg hh ii jj kk"           '  Word(s) Keys like       "Excel Fox, Eilen's Lounge
       sp = Split("mm nn oo pp qq rr ss tt uu vv ww")     '  1 D array of URLs like    "https://eileenslounge.com, https://www.excelfox.com
       
       c01 = "dd"                   '  an example word key
       MsgBox sp(UBound(Split(Split(c00, c01)(0))))
    End Sub
    It don’t work quite as I wanted it to:-
    _ It is not case insensitive on the key word, - my fault I did not make that clear. I can get over that by doing some UCase( )
    _ It returns a (wrong) answer instead of a "" if it does not find the word key. I will have to add a check for that. Probably the way my coding does that, something of this form will do, and make comparing of the codings easier,
    If InStr(1, strItAll, SelTxt, vbTextCompare) > 0 Then

    What’s the basic idea
    There are some useful ideas hidden in it.
    The main one is that splitting a text string by the thing you are looking for, ( along with a few other things ), as another way to get the position of it, so like a sort of alternative to InStr way to get at position something in a string

    This is an opened up version of Sub M_snb()

    Code:
    Sub SplitytySplit_M_snb_()   '    https://www.excelfox.com/forum/showthread.php/2860-Notes-tests-string-manipulation-of-text-files-and-string-manipulations?p=24093&viewfull=1#post24093
    Dim WdEileen As String, WdFox As String
     Let WdEileen = "Eileen's Lounge,eileenslounge,The Windows Clipboard,"
     Let WdFox = "Excel Fox,excelfox,"
    Dim Wdkey As String
     Let Wdkey = UCase(WdEileen & WdFox)                   '  word(s) Keys like       "Excel Fox, Eilen's Lounge
    
    Dim URLEileen As String, URLFox As String
     Let URLEileen = "https://eileenslounge.com/app.php/portal,https://eileenslounge.com/app.php/portal,https://www.eileenslounge.com/viewtopic.php?p=300947#p300947,"
     Let URLFox = "https://www.excelfox.com/forum/forum.php,https://www.excelfox.com/forum/forum.php,"
    Dim URLs As String
     Let URLs = URLEileen & URLFox
    Dim SptURLs() As String
     Let SptURLs() = Split(URLs, ",", -1, vbBinaryCompare)  ' 1 D array of URLs like    "https://eileenslounge.com, https://www.excelfox.com
     
    Dim Excample As String
     Let Excample = UCase("Excel fox")   '  an example  word key
    
    Dim SptOff As String    '  The next few lines give a sort of  InStr  alternative way  to "get at position something in a string"
     Let SptOff = Split(Wdkey, Excample, -1, vbBinaryCompare)(0)
    Dim nth As Long '  This effectively gives us a number which is the Index of both the word key and the URL
     Let nth = UBound(Split(SptOff, ",", -1, vbBinaryCompare))
     Let nth = Len(SptOff) - Len(Replace(SptOff, ",", "", 1, -1, vbBinaryCompare))
     
    Dim wantedURL As String
     Let wantedURL = SptURLs(nth): Debug.Print wantedURL ' gives https://www.excelfox.com/forum/forum.php
    End Sub
    This next version puts it in a form more comparable with my full instr version, Sub InstrIt()


    Code:
    Sub SplitytySplit__()    '    https://www.excelfox.com/forum/showthread.php/2860-Notes-tests-string-manipulation-of-text-files-and-string-manipulations?p=24093&viewfull=1#post24093
    Rem 0  The text you selected
    Dim SelTxt As String
     Let SelTxt = Selection.Text ' A text I highlighted in Word
     Let SelTxt = UCase(SelTxt)
    
    Rem 1 Some groups of   name, URL,   pairs
    Dim WdEileen As String, WdFox As String
     Let WdEileen = "Eileen's Lounge,eileenslounge,The Windows Clipboard,"
     Let WdFox = "Excel Fox,excelfox,"
    Dim Wdkey As String
     Let Wdkey = UCase(WdEileen & WdFox)                   '  word(s) Keys like       "Excel Fox, Eilen's Lounge
    
    Dim URLEileen As String, URLFox As String
     Let URLEileen = "https://eileenslounge.com/app.php/portal,https://eileenslounge.com/app.php/portal,https://www.eileenslounge.com/viewtopic.php?p=300947#p300947,"
     Let URLFox = "https://www.excelfox.com/forum/forum.php,https://www.excelfox.com/forum/forum.php,"
    Dim URLs As String
     Let URLs = URLEileen & URLFox
    Dim SptURLs() As String
     Let SptURLs() = Split(URLs, ",", -1, vbBinaryCompare)  ' 1 D array of URLs like    "https://eileenslounge.com, https://www.excelfox.com
     
    Rem 2 Find the URL , but only  works  if there is one
    Dim SptOff As String    '  The next few lines give a sort of  InStr  alternative way  to "get at position something in a string"
     Let SptOff = Split(Wdkey, SelTxt, -1, vbBinaryCompare)(0)
    Dim nth As Long '  This effectively gives us a number which is the Index of both the word key and the URL
     Let nth = UBound(Split(SptOff, ",", -1, vbBinaryCompare))
     Let nth = Len(SptOff) - Len(Replace(SptOff, ",", "", 1, -1, vbBinaryCompare))
     Let strURL = SptURLs(nth)
    Rem 3 Make the BB Code Tag URL thing
    Call MakeABBCodeTagURL(strURL)
    End Sub
    And here is TLDR version to try and make a better comparison to my shortest version so far, Sub BBCodeTagsURL()
    Code:
    Sub SplitytySplit_TLDR()   '  https://www.excelfox.com/forum/showthread.php/2860-Notes-tests-string-manipulation-of-text-files-and-string-manipulations?p=24093&viewfull=1#post24093
    Rem 0  The text you selected
    Dim SelTxt As String
     Let SelTxt = UCase(Selection.Text) ' A text I highlighted in Word in  UCase  as part of way to get the key text search case insensitive
    
    Rem 1 Some groups of   name, URL,   pairs
    Dim WdEileen As String, WdFox As String
     Let WdEileen = "Eileen's Lounge,eileenslounge,The Windows Clipboard,"
     Let WdFox = "Excel Fox,excelfox,"
    Dim Wdkey As String
     Let Wdkey = UCase(WdEileen & WdFox)                   '  word(s) Keys like       "Excel Fox, Eilen's Lounge
    
    Dim URLEileen As String, URLFox As String
     Let URLEileen = "https://eileenslounge.com/app.php/portal,https://eileenslounge.com/app.php/portal,https://www.eileenslounge.com/viewtopic.php?p=300947#p300947,"
     Let URLFox = "https://www.excelfox.com/forum/forum.php,https://www.excelfox.com/forum/forum.php,"
    Dim URLs As String
     Let URLs = URLEileen & URLFox
                                'Dim SptURLs() As String
                                ' Let SptURLs() = Split(URLs, ",")  ' 1 D array of URLs like    "https://eileenslounge.com, https://www.excelfox.com
     
    Rem 2 Find the URL if there is one, or make   ""   if no match
    Dim strURL As String
        If InStr(1, Wdkey, SelTxt, vbTextCompare) > 0 Then
         Let strURL = Split(URLs, ",")(UBound(Split(Split(Wdkey, SelTxt)(0), ",")))
        Else
         Let strURL = ""
        End If
    Rem 3 Make the BB Code Tag URL thing
    Call MakeABBCodeTagURL(strURL)
    End Sub
    Conclusion
    Rem 2 is probably the best part to compare. The main coding line
    Split(URLs, ",")(UBound(Split(Split(Wdkey, SelTxt)(0), ",")))
    looks a bit better in snb’s than mine,
    Mid(strItAll, InStr(InStr(1, strItAll, SelTxt, vbTextCompare), strItAll, "http", vbBinaryCompare), InStr(InStr(InStr(1, strItAll, SelTxt, vbTextCompare), strItAll, "http", vbBinaryCompare), strItAll, ",", vbBinaryCompare) - InStr(InStr(1, strItAll, SelTxt, vbTextCompare), strItAll, "http", vbBinaryCompare))


    A lesser point possibly is that adding more pairs is slightly more difficult, and prone to mistakes in snb’s as the key word and the URL go in different places.

    (I noticed something new, or better said something I overlooked: Both mine and snb’s coding here will get you a URL string likely to be the one you want if you select only part of the text and then run the coding.
    In these examples, for example, if selecting
    Excel FoX
    , and running the coding got you this in the Microsoft Word document,
    [URL=https://www.excelfox.com/forum/forum.php] Excel FoX [/url]
    (, so in the final forum post you would get this Excel FoX )

    , then selecting
    oX
    , and running the coding would get you this in the Microsoft Word document
    Excel F[URL=https://www.excelfox.com/forum/forum.php]oX [/url]
    (, and in the final forum post you would get this
    Excel FoX
    I suspect that would be more useful than not, but I might change my opinion as time goes on and the number of key word , URL link pairs increases, as that might increase the occurrence of the coding getting the wrong URL, as there will be more likelyhood of a short text being found in more key words
    )
    Last edited by DocAElstein; 03-28-2024 at 03:12 AM.

  5. #105
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,466
    Rep Power
    10
    Some extended notes for this main forum post
    https://eileenslounge.com/viewtopic....a7d27b#p315620
    https://eileenslounge.com/viewtopic.php?p=315620&sid=922f8eb190547f727ca48c954aa7d27b#p315620
    This is post
    https://www.excelfox.com/forum/showt...l=1#post240923
    https://www.excelfox.com/forum/showthread.php/2860-Notes-tests-string-manipulation-of-text-files-and-string-manipulations?p=24093&viewfull=1#post24093








    snb's offerings, for Word VBA / VBA alternative for App Match of Excel VBA


    Code:
    Sub M_snb_000()   '   https://eileenslounge.com/viewtopic.php?p=315620#p315620
       sp = Split("aa_mm bb_nn cc_oo dd_pp ee_qq ff_rr gg_ss hh_tt ii_uu jj_vv kk_ww")
       
       c01 = "dd"
       MsgBox Split(Filter(sp, c01)(0), "_")(1)
    End Sub
    
    Similar to the last offering , its not working case insensitive for the key word, and for no match it will not work, in this case it will error
    This time we have a simple modification to get the case insensitive, changing in the Filter( ) function,
    Compare:=vbBinaryCompare
    , to
    Compare:= vbTextCompare
    To stop the error and give me a "" instead if no match is found, I will once again use my If
    InStr(1, strItAll, SelTxt, vbTextCompare) > 0 Then
    , for ease of comparison.
    ( The coding also has the feature of working if only a portion of the key word(s) are selected )

    What’s the basic idea
    The use of the Filter( ) function gives a very nice simple way to get at the pair, from which it is child’s play to get the second bit, the URL.
    This coding also takes the pair as a pair, which is preferable for me.


    Here is a full open ed up code version of the basic snb offering

    Code:
    Sub SplitFilterM_snb_000()  '    https://www.excelfox.com/forum/showthread.php/2860-Notes-tests-string-manipulation-of-text-files-and-string-manipulations?p=24094&viewfull=1#post24094
    
    Dim strItAll As String, strEileen As String, strFox As String
     Let strEileen = "Eileen's Lounge_https://eileenslounge.com/app.php/portal, eileenslounge_https://eileenslounge.com/app.php/portal, The Windows Clipboard,_https://www.eileenslounge.com/viewtopic.php?p=300947#p300947, "
     Let strFox = "Excel Fox_https://www.excelfox.com/forum/forum.php, excelfox_https://www.excelfox.com/forum/forum.php, "
     
     Let strItAll = strEileen & strFox
    
    Dim SptstrItAll() As String
     Let SptstrItAll() = Split(strItAll, ", ", -1, vbBinaryCompare)  ' 1 D array of pairs like  eileenslounge_https://eileenslounge.com/app.php/portal    The Windows Clipboard,_https://www.eileenslounge.com/viewtopic.php?p=300947#p300947,
    
    Dim Excample As String
     Let Excample = "ox"   '  an example  word key
    
    Dim FltIt As String  ' This should return the wanted pair -   The  Filter( )   function returns a subset array, ( of one element in this case ) , the element will be that incuding the search text,  Excample        The  (0) is the first element , the only one
     Let FltIt = Filter(SptstrItAll(), Excample, Include:=True, Compare:=vbBinaryCompare)(0)
    
    Dim wantedURL As String
     Let wantedURL = Split(FltIt, "_", -1, vbBinaryCompare)(1): Debug.Print wantedURL ' gives https://www.excelfox.com/forum/forum.php    the second element of the found pair string is the URL
    
    End Sub
    This next version puts it in a form more comparable with my full instr version, Sub InstrIt()


    Code:
    Sub SplitFilter() '    https://www.excelfox.com/forum/showthread.php/2860-Notes-tests-string-manipulation-of-text-files-and-string-manipulations?p=24094&viewfull=1#post24094      https://eileenslounge.com/viewtopic.php?p=315620#p315620
    Rem 0  The text you selected
    Dim SelTxt As String
     Let SelTxt = Selection.Text ' A text I highlighted in Word
    
    Rem 1 Some groups of   name_URL   pairs
    Dim strItAll As String, strEileen As String, strFox As String
     Let strEileen = "Eileen's Lounge_https://eileenslounge.com/app.php/portal, eileenslounge_https://eileenslounge.com/app.php/portal, The Windows Clipboard,_https://www.eileenslounge.com/viewtopic.php?p=300947#p300947, "
     Let strFox = "Excel Fox_https://www.excelfox.com/forum/forum.php, excelfox_https://www.excelfox.com/forum/forum.php, "
     
     Let strItAll = strEileen & strFox
    
    Dim SptstrItAll() As String
     Let SptstrItAll() = Split(strItAll, ", ", -1, vbBinaryCompare)  ' 1 D array of pairs like  eileenslounge_https://eileenslounge.com/app.php/portal    The Windows Clipboard,_https://www.eileenslounge.com/viewtopic.php?p=300947#p300947,
    
    Rem 2 Find the URL but this will error if there is not one
    Dim FltIt As String  ' This should return the wanted pair -   The  Filter( )   function returns a subset array, ( of one element in this case ) , the element will be that incuding the search text,  Excample        The  (0) is the first element , the only one
     Let FltIt = Filter(SptstrItAll(), SelTxt Include:=True, Compare:=vbTextCompare)(0)
    Dim strURL As String
     Let strURL = Split(FltIt, "_", -1, vbBinaryCompare)(1)
    
    Rem 3 Make the BB Code Tag URL thing
    Call MakeABBCodeTagURL(strURL)
    End Sub

    And here is TLDR version to try and make a better comparison to my shortest version so far, Sub BBCodeTagsURL()

    Code:
    Sub SplitFilter_TLDR() '    https://www.excelfox.com/forum/showthread.php/2860-Notes-tests-string-manipulation-of-text-files-and-string-manipulations?p=24094&viewfull=1#post24094      https://eileenslounge.com/viewtopic.php?p=315620#p315620
    Rem 0  The text you selected
    Dim SelTxt As String
     Let SelTxt = Selection.Text ' A text I highlighted in Word
    
    Rem 1 Some groups of   name_URL   pairs
    Dim strItAll As String, strEileen As String, strFox As String
     Let strEileen = "Eileen's Lounge_https://eileenslounge.com/app.php/portal, eileenslounge_https://eileenslounge.com/app.php/portal, The Windows Clipboard,_https://www.eileenslounge.com/viewtopic.php?p=300947#p300947, "
     Let strFox = "Excel Fox_https://www.excelfox.com/forum/forum.php, excelfox_https://www.excelfox.com/forum/forum.php, "
     
     Let strItAll = strEileen & strFox
    
                                                                                            'Dim SptstrItAll() As String
                                                                                            ' Let SptstrItAll() = Split(strItAll, ", ")  ' 1 D array of pairs like  eileenslounge_https://eileenslounge.com/app.php/portal    The Windows Clipboard,_https://www.eileenslounge.com/viewtopic.php?p=300947#p300947,
    Rem 2 Find the URL if there is one
    Dim strURL As String
        If InStr(1, strItAll, SelTxt, vbTextCompare) > 0 Then
         Let strURL = Split(Filter(Split(strItAll, ", "), SelTxt, True, vbTextCompare)(0), "_")(1)
        Else
         Let strURL = ""
        End If
    Rem 3 Make the BB Code Tag URL thing
    Call MakeABBCodeTagURL(strURL)
    End Sub

    Conclusions
    The main coding line
    Split(Filter(Split(strItAll, ", "), SelTxt, True, vbTextCompare)(0), "_")(1)
    looks nice compared with mine
    Mid(strItAll, InStr(InStr(1, strItAll, SelTxt, vbTextCompare), strItAll, "http", vbBinaryCompare), InStr(InStr(InStr(1, strItAll, SelTxt, vbTextCompare), strItAll, "http", vbBinaryCompare), strItAll, ",", vbBinaryCompare) - InStr(InStr(1, strItAll, SelTxt, vbTextCompare), strItAll, "http", vbBinaryCompare))

    In addition, I like the way one enters an additional key word_Url pair in one go




    Edit: A slight modification in a follow up post, … ( https://eileenslounge.com/viewtopic....315705#p315705 )
    This,
    Code:
       sp = Split("aa_mm bb_nn cc_oo dd_pp ee_qq ff_rr gg_ss hh_tt ii_uu jj_vv kk_ww")
       
       c01 = "dd"
       MsgBox Split(Filter(sp, c01)(0), "_")(1)
    , Changed to
    Code:
       sp = Split("aa_mm bb_nn cc_oo dd_pp ee_qq ff_rr DD_ss hh_tt Dd_uu jj_vv kk_ww")
       
       c01 = "DD"
       c02 = ""
       sn = Filter(sp, c01,,1)
       If UBound(sn) > -1 Then c02 = Split(Filter(sp, c01,,1)(0), "_")(1)   
       MsgBox c02
    For consistency / less confusingly comparison/ and to make the comparisons generally that I am doing a bit easier, we can say you changed this ,
    Code:
       sp = Split("aa_mm bb_nn cc_oo dd_pp ee_qq ff_rr gg_ss hh_tt ii_uu jj_vv kk_ww")
       
       c01 = "dd"
       MsgBox Split(Filter(sp, c01)(0), "_")(1)
    , to this
    Code:
      '  c02 = ""
       sp = Split("aa_mm bb_nn cc_oo dd_pp ee_qq ff_rr DD_ss hh_tt Dd_uu jj_vv kk_ww")
       
       c01 = "DD"
       If UBound(Filter(sp, c01, , 1)) > -1 Then
       MsgBox Split(Filter(sp, c01, , Compare:=vbTextCompare)(0), "_")(1)      '  See Settings  https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/filter-function
       End If
    So you
    _(i) use the Compare:=vbTextCompare in the filter function as I did to get the case insensibility,
    _(ii) The If UBound(Filter(sp, c01, , 1)) > -1 is effectively an alternative to my If InStr(1, strItAll, SelTxt, vbTextCompare) > 0
    Specifically in my TLDR versions , this line would be that alternative, If UBound(Filter(Split(strItAll, ", "), SelTxt, True, vbTextCompare)) > -1
    _(iiI) you noticed, as SpeakEasy did, that I had an unnecessary Else bit to make the URL string "" for no match, since the variable would be already at that "" ( I am not sure why you did the c02 = "" though? Perhaps because as you don’t generally declare your variables. Whilst that does not seem to give us problems in the demo coding so far, maybe it could in some other variation of the coding – I mean there might be a situation where the use of an undefined variable might cause Excel not to take it as a zero length string, "" , but rather, it might take it as something else which might then chuck a spanner in the works?)
    Attached Files Attached Files
    Last edited by DocAElstein; 03-29-2024 at 07:05 PM.

  6. #106
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,466
    Rep Power
    10
    Some extended notes for replies to these main forum posts
    https://eileenslounge.com/viewtopic....315705#p315705
    https://eileenslounge.com/viewtopic....315689#p315689
    This is post
    https://www.excelfox.com/forum/showt...ll=1#post24103
    https://www.excelfox.com/forum/showthread.php/2860-Notes-tests-string-manipulation-of-text-files-and-string-manipulations?p=24103&viewfull=1#post24103







    Here is another set of TLDR versions. The SplitFilter one from snb has not changed too much. There is a new dic one from SpeakEasy

    Code:
    
    
    ' ===================================
    
    '    https://eileenslounge.com/viewtopic.php?p=315705#p315705
    '    https://eileenslounge.com/viewtopic.php?p=315689#p315689
    
    
    Sub BBCodeTagsURLb()  '     https://eileenslounge.com/viewtopic.php?p=315503#p315503  https://www.excelfox.com/forum/showthread.php/2860-Notes-tests-string-manipulation-of-text-files-and-string-manipulations?p=24092&viewfull=1#post24092
    Rem 0  The text you selected
    Dim SelTxt As String
     Let SelTxt = Selection.Text ' A text I highlighted in Word
    
    Rem 1 Some groups of   name, URL,   pairs
    Dim strItAll As String, strEileen As String, strFox As String
     Let strEileen = "Eileen's Lounge, https://eileenslounge.com/app.php/portal, eileenslounge, https://eileenslounge.com/app.php/portal, The Windows Clipboard, https://www.eileenslounge.com/viewtopic.php?p=300947#p300947, "
     Let strFox = "Excel Fox, https://www.excelfox.com/forum/forum.php, excelfox, https://www.excelfox.com/forum/forum.php, "
     
     Let strItAll = strEileen & strFox
    
    Rem 2 Find the URL if there is one
    Dim strURL As String
        If InStr(1, strItAll, SelTxt, vbTextCompare) > 0 Then
         Let strURL = Mid(strItAll, InStr(InStr(1, strItAll, SelTxt, vbTextCompare), strItAll, "http", vbBinaryCompare), InStr(InStr(InStr(1, strItAll, SelTxt, vbTextCompare), strItAll, "http", vbBinaryCompare), strItAll, ",", vbBinaryCompare) - InStr(InStr(1, strItAll, SelTxt, vbTextCompare), strItAll, "http", vbBinaryCompare))
        Else
    '     Let strURL = ""
        End If
    
    Rem 3 Make the BB Code Tag URL thing
    Call MakeABBCodeTagURL(strURL)
    
    End Sub
    Sub SplitytySplit_TLDRb()    '  https://www.excelfox.com/forum/showthread.php/2860-Notes-tests-string-manipulation-of-text-files-and-string-manipulations?p=24093&viewfull=1#post24093
    Rem 0  The text you selected
    Dim SelTxt As String
     Let SelTxt = UCase(Selection.Text) ' A text I highlighted in Word in  UCase  as part of way to get the key text search case insensitive
    
    Rem 1 Some groups of   name, URL,   pairs
    Dim WdEileen As String, WdFox As String
     Let WdEileen = "Eileen's Lounge,eileenslounge,The Windows Clipboard,"
     Let WdFox = "Excel Fox,excelfox,"
    Dim Wdkey As String
     Let Wdkey = UCase(WdEileen & WdFox)                   '  word(s) Keys like       "Excel Fox, Eilen's Lounge
    
    Dim URLEileen As String, URLFox As String
     Let URLEileen = "https://eileenslounge.com/app.php/portal,https://eileenslounge.com/app.php/portal,https://www.eileenslounge.com/viewtopic.php?p=300947#p300947,"
     Let URLFox = "https://www.excelfox.com/forum/forum.php,https://www.excelfox.com/forum/forum.php,"
    Dim URLs As String
     Let URLs = URLEileen & URLFox
                                'Dim SptURLs() As String
                                ' Let SptURLs() = Split(URLs, ",")  ' 1 D array of URLs like    "https://eileenslounge.com, https://www.excelfox.com
     
    Rem 2 Find the URL if there is one
    Dim strURL As String
        If InStr(1, Wdkey, SelTxt, vbTextCompare) > 0 Then
         Let strURL = Split(URLs, ",")(UBound(Split(Split(Wdkey, SelTxt)(0), ",")))
        Else
    '     Let strURL = ""
        End If
    
    Rem 3 Make the BB Code Tag URL thing
    Call MakeABBCodeTagURL(strURL)
    End Sub
    Sub SplitFilter_TLDRb() '    https://www.excelfox.com/forum/showthread.php/2860-Notes-tests-string-manipulation-of-text-files-and-string-manipulations?p=24094&viewfull=1#post24094      https://eileenslounge.com/viewtopic.php?p=315620#p315620
    Rem 0  The text you selected
    Dim SelTxt As String
     Let SelTxt = Selection.Text ' A text I highlighted in Word
    
    Rem 1 Some groups of   name_URL   pairs
    Dim strItAll As String, strEileen As String, strFox As String
     Let strEileen = "Eileen's Lounge_https://eileenslounge.com/app.php/portal, eileenslounge_https://eileenslounge.com/app.php/portal, The Windows Clipboard,_https://www.eileenslounge.com/viewtopic.php?p=300947#p300947, "
     Let strFox = "Excel Fox_https://www.excelfox.com/forum/forum.php, excelfox_https://www.excelfox.com/forum/forum.php, "
     
     Let strItAll = strEileen & strFox
    
                                                                                            'Dim SptstrItAll() As String
                                                                                            ' Let SptstrItAll() = Split(strItAll, ", ")  ' 1 D array of pairs like  eileenslounge_https://eileenslounge.com/app.php/portal    The Windows Clipboard,_https://www.eileenslounge.com/viewtopic.php?p=300947#p300947,
    Rem 2 Find the URL if there is one
    Dim strURL As String
        If InStr(1, strItAll, SelTxt, vbTextCompare) > 0 Then
      '  If UBound(Filter(Split(strItAll, ", "), SelTxt, True, vbTextCompare)) > -1 Then
         Let strURL = Split(Filter(Split(strItAll, ", "), SelTxt, True, vbTextCompare)(0), "_")(1)
        Else
    '     Let strURL = ""
        End If
    Rem 3 Make the BB Code Tag URL thing
    Call MakeABBCodeTagURL(strURL)
    End Sub
    
    Sub BBCodeTagsURLDictionaryb()
        Rem 0  The text you selected
    Dim mydic As New Scripting.Dictionary  ' Early Binding referrence   https://i.postimg.cc/mgKt2QgN/Microsoft-Scripting-Runtime.jpg
    Dim SelTxt As String, strURL As String
     Let SelTxt = UCase(Trim$(Selection.Text)) ' A text I highlighted in Word
        
    Rem 1 Some groups of   name, URL,   pairs
    ' Eileen's Lounge
    mydic.Add UCase("Eileen's Lounge"), "https://eileenslounge.com/app.php/portal"
    mydic.Add UCase("eileenslounge"), "https://eileenslounge.com/app.php/portal"
    mydic.Add UCase("The Windows Clipboard"), "https://www.eileenslounge.com/viewtopic.php?p=300947#p300947"
    ' Excel Fox stuff
    mydic.Add UCase("Excel Fox"), "https://www.excelfox.com/forum/forum.php"
    mydic.Add UCase("excelfox"), "https://www.excelfox.com/forum/forum.php"
         
        
    Rem 2 Find the URL if there is one
        If mydic.Exists(SelTxt) Then
         Let strURL = mydic(SelTxt)
      '  Else
        End If
        
    Rem 3 Make the BB Code Tag URL thing
    Call MakeABBCodeTagURL(strURL)
    End Sub
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    Sub MakeABBCodeTagURL(ByVal strURL As String) ' https://www.excelfox.com/forum/showthread.php/2860-Notes-tests-string-manipulation-of-text-files-and-string-manipulations?p=24092&viewfull=1#post24092
        With Selection
         .Text = " " & .Text & " "
         .Collapse Direction:=wdCollapseEnd
         .Font.Color = wdColorAutomatic
        End With
    End Sub
    
    Attached Files Attached Files
    Last edited by DocAElstein; 03-30-2024 at 01:49 AM.

  7. #107
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,466
    Rep Power
    10
    Some extended notes for replies to these main forum posts
    https://eileenslounge.com/viewtopic....315849#p315849
    https://eileenslounge.com/viewtopic....315754#p315754
    This is post
    https://www.excelfox.com/forum/showt...ll=1#post24094
    https://www.excelfox.com/forum/showthread.php/2860-Notes-tests-string-manipulation-of-text-files-and-string-manipulations?p=24094&viewfull=1#post24094







    Another snb offering , ( a couple ),- so lets take a look at snb’s dic first, not necessarily a pretty sight, but never mind.
    Code:
     Sub snb_dic()  '      To use a dictionary I would write it this way:  https://eileenslounge.com/viewtopic.php?p=315849#p315849
      c00 = Selection
      With CreateObject("scripting.dictionary")
        .Item(UCase("Eileen's Lounge")) = "https://eileenslounge.com/app.php/portal"
        .Item(UCase("eileenslounge")) = "https://eileenslounge.com/app.php/portal"
        .Item(UCase("The Windows Clipboard")) = "https://www.eileenslounge.com/viewtopic.php?p=300947#p300947"
        .Item(UCase("Excel Fox")) = "https://www.excelfox.com/forum/forum.php"
        .Item(UCase("excelfox")) = "https://www.excelfox.com/forum/forum.php"
          
         MsgBox .Item(UCase(c00))
      End With
    End Sub
    
    Sub snb_docv()  '      In Word you can also use the docvariables:    https://eileenslounge.com/viewtopic.php?p=315849#p315849
        c00 = Selection  
       With ThisDocument
        .Variables(UCase("Eileen's Lounge")) = "https://eileenslounge.com/app.php/portal"
        .Variables(UCase("eileenslounge")) = "https://eileenslounge.com/app.php/portal"
        .Variables(UCase("The Windows Clipboard")) = "https://www.eileenslounge.com/viewtopic.php?p=300947#p300947"
        .Variables(UCase("Excel Fox")) = "https://www.excelfox.com/forum/forum.php"
        .Variables(UCase("excelfox")) = "https://www.excelfox.com/forum/forum.php"
          
         MsgBox .Variables(UCase(c00))
      End With
    End Sub
    First, snb either noticed, or didn’t, that a If dic.Exists(SelTxt) Then is never needed. The same goes for SpeakEasy’s dic, so let’s first get those two up in a better comparison for, snb’s and SpeakEasy’s dic
    Code:
    '      https://eileenslounge.com/viewtopic.php?p=315849#p315849
    Sub snb_dicc_TLDR()  '  https://www.excelfox.com/forum/showthread.php/2860-Notes-tests-string-manipulation-of-text-files-and-string-manipulations?p=24094&viewfull=1#post24094
    Rem 0  The text you selected
     Let SelTxt = UCase(Trim$(Selection.Text)) ' A text I highlighted in Word
        
    Rem 1 Some groups of   name, URL,   pairs
        With CreateObject("scripting.dictionary")
    ' Eileen's Lounge
        .Item(UCase("Eileen's Lounge")) = "https://eileenslounge.com/app.php/portal"
        .Item(UCase("eileenslounge")) = "https://eileenslounge.com/app.php/portal"
        .Item(UCase("The Windows Clipboard")) = "https://www.eileenslounge.com/viewtopic.php?p=300947#p300947"
    ' Excel Fox stuff
        .Item(UCase("Excel Fox")) = "https://www.excelfox.com/forum/forum.php"
        .Item(UCase("excelfox")) = "https://www.excelfox.com/forum/forum.php"
        
    Rem 2 Find the URL if there is one
    Dim strURL As String
         Let strURL = .Item(SelTxt)
      End With
    Rem 3 Make the BB Code Tag URL thing
    Call MakeABBCodeTagURL(strURL)
    End Sub
    
    Code:
    Sub BBCodeTagsURLDictionaryd()
        Rem 0  The text you selected
    Dim mydic As New Scripting.Dictionary  ' Early Binding referrence   https://i.postimg.cc/mgKt2QgN/Microsoft-Scripting-Runtime.jpg
    Dim SelTxt As String, strURL As String
     Let SelTxt = UCase(Trim$(Selection.Text)) ' A text I highlighted in Word
        
    Rem 1 Some groups of   name, URL,   pairs
    ' Eileen's Lounge
        mydic.Add Key:=UCase("Eileen's Lounge"), Item:="https://eileenslounge.com/app.php/portal"
        mydic.Add Key:=UCase("eileenslounge"), Item:="https://eileenslounge.com/app.php/portal"
        mydic.Add Key:=UCase("The Windows Clipboard"), Item:="https://www.eileenslounge.com/viewtopic.php?p=300947#p300947"
    ' Excel Fox stuff
        mydic.Add Key:=UCase("Excel Fox"), Item:="https://www.excelfox.com/forum/forum.php"
        mydic.Add Key:=UCase("excelfox"), Item:="https://www.excelfox.com/forum/forum.php"
         
    Rem 2 Find the URL if there is one
    Dim strURL As String
         Let strURL = mydic(SelTxt)
        
    Rem 3 Make the BB Code Tag URL thing
    Call MakeABBCodeTagURL(strURL)
    End Sub
    Maybe the main diffference now is that the filling looks just slightly tidier

    _.________________________________________________ _________________________________________________
    Code:
    Sub snb_docv()  '      In Word you can also use the docvariables:    https://eileenslounge.com/viewtopic.php?p=315849#p315849
        c00 = Selection  
       With ThisDocument
        .Variables(UCase("Eileen's Lounge")) = "https://eileenslounge.com/app.php/portal"
        .Variables(UCase("eileenslounge")) = "https://eileenslounge.com/app.php/portal"
        .Variables(UCase("The Windows Clipboard")) = "https://www.eileenslounge.com/viewtopic.php?p=300947#p300947"
        .Variables(UCase("Excel Fox")) = "https://www.excelfox.com/forum/forum.php"
        .Variables(UCase("excelfox")) = "https://www.excelfox.com/forum/forum.php"
          
         MsgBox .Variables(UCase(c00))
      End With
    End Sub
    The document variable looked initially interesting. It seems to be like a simplified dictionary. The disadvantage here seems to be that if the document variable does not exist, then attempting to get that non-existent variable, will error. There is no simple way, for example there is no equivalent of the dictionary If dic.Exists(SelTxt) Then
    Probably error handling would be the only simple way to do a check. We usually all frown a bit on error handling, if we can do without it. So unless this document variable way has significant other advantages that I don’t know about, then, whilst it certainly is interesting to know about it, I think, for now, it does not get on my short list, or at least low down the list. Shame as my initial thoughts were that it might be some sort of word dedicated and optimised type of dictionary. So then I would have had it all neatly in in word.
    I wonder if possibly Error handling in VBA has a different reputation in Word as Excel? My opinion of it as a bad thing comes from partly from the average smarter Excel person than me in who more often than not says it’s a bad thing if you can find a way to do without it.

    Anyway, this would be the equivalent short coding equivalent for the document variable way
    Code:
    '      https://eileenslounge.com/viewtopic.php?p=315849#p315849
    Sub snb_docvc_TLDR()  '  https://www.excelfox.com/forum/showthread.php/2860-Notes-tests-string-manipulation-of-text-files-and-string-manipulations?p=24094&viewfull=1#post24094
    Dim strURL As String, SelTxt As String
    Rem 0  The text you selected
     Let SelTxt = UCase(Trim$(Selection.Text)) ' A text I highlighted in Word
        
    Rem 1 Some groups of   name, URL,   pairs
        With ThisDocument
    ' Eileen's Lounge
        .Variables(UCase("Eileen's Lounge")) = "https://eileenslounge.com/app.php/portal"
        .Variables(UCase("eileenslounge")) = "https://eileenslounge.com/app.php/portal"
        .Variables(UCase("The Windows Clipboard")) = "https://www.eileenslounge.com/viewtopic.php?p=300947#p300947"
    ' Excel Fox stuff
        .Variables(UCase("Excel Fox")) = "https://www.excelfox.com/forum/forum.php"
        .Variables(UCase("excelfox")) = "https://www.excelfox.com/forum/forum.php"
        
    Rem 2 Find the URL if there is one
        On Error Resume Next
         Let strURL = .Variables(SelTxt)
        On Error GoTo 0
        End With
    Rem 3 Make the BB Code Tag URL thing
    Call MakeABBCodeTagURL(strURL)
    End Sub



    Something like this would add the two latest snb offerings to the main bit to make comparisons from, at least as regards the main working bit of the coding ( correcting SpeakEasy’s dic to remove the If mydic.Exists( bit

    Code:
        If InStr(1, strItAll, SelTxt, vbTextCompare) > 0 Then
         Let strURL = Mid(strItAll, InStr(InStr(1, strItAll, SelTxt, vbTextCompare), strItAll, "http", vbBinaryCompare), InStr(InStr(InStr(1, strItAll, SelTxt, vbTextCompare), strItAll, "http", vbBinaryCompare), strItAll, ",", vbBinaryCompare) - InStr(InStr(1, strItAll, SelTxt, vbTextCompare), strItAll, "http", vbBinaryCompare))
    
        If InStr(1, Wdkey, SelTxt, vbTextCompare) > 0 Then
         Let strURL = Split(URLs, ",")(UBound(Split(Split(Wdkey, SelTxt)(0), ",")))
    
        If InStr(1, strItAll, SelTxt, vbTextCompare) > 0 Then
      '  If UBound(Filter(Split(strItAll, ", "), SelTxt, True, vbTextCompare)) > -1 Then
         Let strURL = Split(Filter(Split(strItAll, ", "), SelTxt, True, vbTextCompare)(0), "_")(1)
    
         Let strURL = mydic(SelTxt)    '   SpeakEasy dic
    
         Let strURL = .Item(SelTxt)     '   snb dic
    
        On Error Resume Next
         Let strURL = .Variables(SelTxt)  '   document variable way
        On Error GoTo 0
    Not so much difference with Speakeasy’s dic or snb’s dic. People’s opinions differ a bit about the With CreateObject( being good because you do away with an object variable. Personally I am less keen most of the time with the With and End With pair, but in some uses I quite like it, the With CreateObject( being one of them

    The document variable way is new to me, so I will reserve judgment on that one just now. Perhaps smarter Word experts passing might at some time have a comment on it or advice about it?
    Attached Files Attached Files
    Last edited by DocAElstein; 04-03-2024 at 01:15 AM.

  8. #108
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,466
    Rep Power
    10
    HCKJ
    Last edited by DocAElstein; 04-02-2024 at 06:31 PM.

  9. #109
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,466
    Rep Power
    10
    LATER
    Seasonal greetings :-)

  10. #110
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,466
    Rep Power
    10
    Later

Similar Threads

  1. Replies: 114
    Last Post: 03-04-2024, 02:39 PM
  2. Replies: 4
    Last Post: 10-02-2022, 09:18 PM
  3. Replies: 4
    Last Post: 01-30-2022, 04:05 PM
  4. Replies: 0
    Last Post: 07-08-2020, 04:29 PM
  5. string manipulation
    By kylefoley76 in forum Excel Help
    Replies: 5
    Last Post: 02-20-2014, 12:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •