Results 1 to 10 of 110

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

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #29
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,316
    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.

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
  •