Results 1 to 10 of 40

Thread: test BB Code

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,313
    Rep Power
    10
    Just some further Testing, as I may have another solution to the problem of codes pasted into a HTML ( or PHP ) Window "Loosing" a carriage return"

    To remind ( me! ) of what i am testing out here: Sometimes it is better to use A HTML ( or PHP ) Code window rather than a BB Code Window to paste in a Forum Post. This can be the case, for example, when a Code itself contains text strings which may have BB Code Tags in. ( The Code tags usually are recognised as just that giving some peculiar results. )

    This Code for example, shown here excactly as I want it, would get messed up in a code Window

    Sub CodeLinesInHTMLWindowLoosingCarriageReturns()
    1 'Line 1
    2 'Line 2
    3 'Line 3
    4 Dim strBBCodeTag As String
    5 Let strBBCodeTag = "[color=lightsalmon]A Text in Forum Post to come out Light Salmon in Color[/color]"
    End Sub

    _................................................. ....

    Pasted in a code Window:

    Code:
    Sub CodeLinesInHTMLWindowLoosingCarriageReturns()1 'Line 1
    2 'Line 2
    3 'Line 3
    4 Dim strBBCodeTag As String
    5 Let strBBCodeTag = "A Text in Forum Post to come out Light Salmon in Color"
    End Sub
    You see the BB Code String was evaluated literally as BB Code. - The BB Code string is messed up as I do not want
    _.............................................

    It is found that pasting in a HTML Code window instead can give you this

    HTML Code:
    Sub CodeLinesInHTMLWindowLoosingCarriageReturns()
    1 'Line 1
    2 'Line 2
    3 'Line 3
    4 Dim strBBCodeTag As String
    5 Let strBBCodeTag = "[color=lightsalmon]A Text in Forum Post to come out Light Salmon in Color[/color]"
    End Sub
    which is again what I wanted
    _...............................................


    But if you paste directly by copying from the VB Editor ( Ctrl C ) and pasting in the forum Editor in HTML Code tags, then you can get this instead.

    HTML Code:
    Sub CodeLinesInHTMLWindowLoosingCarriageReturns()1 'Line 12 'Line 23 'Line 34 Dim strBBCodeTag As String5 Let strBBCodeTag = "[color=lightsalmon]A Text in Forum Post to come out Light Salmon in Color[/color]"End Sub
    . here the carriage retzurns have "vanished "

    _................................................. ..................................


    _ I noticed and demonstrated that you can get over this sometimes by “doing a stop over “ in between at a a Word Document, that is to say pasting into a Word document first , then re – copying that to the clipboard and pasting that into the Forum Editor.
    http://www.excelfox.com/forum/f17/te...2079/#post9641
    http://www.excelfox.com/forum/f13/bb...2077/#post9645
    _..............................................

    OK that was one “workaround”..... _The other Day I had a similar problem (_.......... with a code i did to overcome the problem of the Forum Editor “eating” spaces of greater than two. )
    http://www.eileenslounge.com/viewtop...art=20#p176255
    _...............)

    _ Some how this “loss of a carriage return crept in when pasted into a Post, ( even though in Word or in a displayed Message Box, the text i wanted to past in seemed OK ).

    _ After a bit of experimenting I tried a modification which was basically this code line

    = Replace((Text), vbCr, vbCr & vbLf, 1, -1) 'In Text~~,~~~replce a vbCr~~~,~~~with a vbCr & vbLf~~~~,~~~~the returned string should start at position 1 of the original ( so whole string returned )(Note: the number is not just where you start replacing- it is also where the returned String may start-so a number greater than 1 will "chop" bits off returning a string of reduced length compared with the original~~~,~~~-1~~indicates replace all occurrences

    Writing a code to do something similar to the text held in the Clipboard appears to do something similar ( Not quite the same .. here what the Message box shows for the “Before” and “after” is different, which was not the case with the modification to the “preventing Forum editor eating spaces more than 2 codes” . Clearly the vbCr and vbLf is a trick one.. )

    _.................

    So Finally
    _ If you wish to use the HTML Code Window rather than the BB Code Window when posting a Code in a Forum Thread.... you

    _ Copy the code from the VB Editor, ( Ctrl C )
    _ Run this code, ( which works on and modifies the text in the Clipboard.

    Code:
    Sub PutInAvbLfInClipboadText() '    "Replcace vbCr with vbCr & vbLf "
    'Get Current Text from Clipboard
    Dim objDat As dataobject
    Set objDat = New dataobject 'Set to a new Instance ( Blue Print ) of dataobject
    'Dim obj As Object
    'Set obj = GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
    objDat.GetFromClipboard 'All that is in the Clipboard goes in this Data Object instance of the Class.
    Let TxtOut = objDat.GetText() 'retrieve the text in this instance of the Class. ( In this case all I have in it is the text typically I think as it is coming from a Ctrl C Copy from the VB Editor )
    Dim originalClipboardText As String: Let originalClipboardText = TxtOut
    Dim TextWithExtravbLF As String
    Let TextWithExtravbLF = Replace(TxtOut, vbCr, vbCr & vbLf, 1, -1)
    'Dump in Clipboard: This second instance of Data Object used to put in Clipboard
    Dim objCliS As dataobject   '**Early Binding.   This is for an Object from the class MS Forms. This will be a Data Object of what we "send" to the Clipboard. So I name it CLIpboardSend. But it is a DataObject. It has the Methods I need to send text to the Clipboard
    Set objCliS = New dataobject '**Must enable Forms Library: In VB Editor do this:  Tools -- References - scroll down to Microsoft Forms 2.0 Object Library -- put checkmark in.  Note if you cannot find it try   OR IF NOT THERE..you can add that manually: VBA Editor -- Tools -- References -- Browse -- and find FM20.DLL file under C:\WINDOWS\system32 and select it --> Open --> OK.
    ' ( or instead of those two lines  Dim obj As New DataObject ).    or  next two lines are.....Late Binding equivalent'
    'Dim obj As Object'  Late Binding equivalent'   If you declare a variable as Object, you are late binding it.  http://excelmatters.com/2013/09/23/vba-references-and-early-binding-vs-late-binding/
    'Set obj = GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")' http://excelmatters.com/2013/10/04/late-bound-msforms-dataobject/
    objCliS.SetText TextWithExtravbLF 'Make Data object's text equal to a copy of ORefiginalText
    objCliS.PutInClipboard 'Place current Data object into the Clipboard
    ' Get from clipboard. This a Another Object from class to be sure we have the data in the Clipboard
    MsgBox prompt:="You dumped in Clipboard originally  this " & vbCr & TxtOut & vbCr & "and if you try to get it, you should get" & vbCr & TextWithExtravbLF & ""
    ' End clean up.
    'TheEnd: ' ( Come here always, even on a unpredictable error )
    Set objDat = Nothing '   Good practice...   maybe....
    Set objCliS = Nothing '  .......   http://www.mrexcel.com/forum/excel-questions/361246-vbnullstring.html#post4414065
    End Sub



    _ Paste into the Forum Thread an enclose in HTML Code Tags..This comes out:

    HTML Code:
    Sub CodeLinesInHTMLWindowLoosingCarriageReturns()
    1 'Line 1
    2 'Line 2
    3 'Line 3
    4 Dim strBBCodeTag As String
    5 Let strBBCodeTag = "[color=lightsalmon]A Text in Forum Post to come out Light Salmon in Color[/color]"
    End Sub

    PHP Code:
    Sub CodeLinesInHTMLWindowLoosingCarriageReturns()
    'Line 1
    2 '
    Line 2
    'Line 3
    4 Dim strBBCodeTag As String
    5 Let strBBCodeTag = "[color=lightsalmon]A Text in Forum Post to come out Light Salmon in Color[/color]"
    End Sub 
    Alan
    Last edited by DocAElstein; 03-09-2016 at 09:14 PM.

Similar Threads

  1. Replies: 12
    Last Post: 09-22-2023, 03:53 PM
  2. Replies: 5
    Last Post: 06-10-2019, 10:14 PM
  3. HTML Code Test --post8798
    By DocAElstein in forum Test Area
    Replies: 19
    Last Post: 06-17-2018, 03:02 PM
  4. CODE TAG Code Test
    By DocAElstein in forum Test Area
    Replies: 5
    Last Post: 09-16-2015, 05:16 PM

Posting Permissions

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