Results 1 to 10 of 51

Thread: ब्लॉग कोशिश कर रहा है بلاگز کی ک*Trying Blogs

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,385
    Rep Power
    10

    Recursion Wonk. To remove BB Code tag pairs incuding nested ones missus

    One problem noted in the previous codes was that the case of nested BB Code tag pairs, the codes did not work. At many forums such nesting of this form is permitted in BB codes.
    [color=Green]Comments [color=Red]Highlight[/color] Comments[/color]
    The returned result is
    Comments Highlight Comments

    None of the codes discussed so far will work for such a case.
    Should the Code tag type be dissimilar, such as_..
    [CENTER][B]Title[/B][/CENTER]
    _..then at least the Find Replace Wildcard Code will work for that by virtue of matching in the String first, for example, in the above example, _..
    __ CENTER __ __ __ __ CENTER __
    _.. then
    __ B __ __ __ __ B __
    However my Long string manipulation code will not even work for that.

    I have done a Long string manipulation code to be discussed in this and the following posts which , I think, work for all situations.

    Brief Descriptions is:
    The entire string is held in a variable, strBBCode. This is declared in a Subroutine. Something similar to that was done for the last code )

    change 1) Minor to last code:
    Unlike the previous codes, ( which sequentially removed BB Code code tags ( by replacing with "" )), the code tags are replaced by some arbitrary character ( This is simply chosen as any not likely to be used as text in the main initial string https://www.mrexcel.com/forum/excel-...ml#post4214083 )

    change 2) Minor
    This itself is not such a major change in the code format, but it facilitates the main change, 3) below. This change is that bulk of the code is within a Function, (Function LongWayOfDoingIt2ReCurseCyClops(__ ) . It is “Called” and needs to be given_..
    _.. the string, strBBCode, By Referral to that variable, rather than its By its Value contents
    and_..
    _.. a Value for the current character position, which initially will be the end ( or length in characters ) position of strBBCode.

    But those are not the main changed characteristic to the code.
    To recap: All my long string manipulation codes, including this Function, have the general characteristic that they loop backwards in the complete string until a ] is found. An attempt is made then to find a [/ . Once this is found an attempt is made to find a ] and then a [ .
    At this point a possible code pair requirement , looking backwards, of ] [/ ] [ is achieved
    ( Reversing that to the correct order shows that clearly more clearly,
    [ _ ] __ [/ _ ],
    or
    [codeText] AnyText [/CodeText] .
    Or
    [Color=red] AnyText [/color]
    _.. etc...)
    Having found a code tag pair, a check is made for its validity ( the same matching work, such as, codetext, color, for example ) , before the adjustments are made to the main string. After that , the code then moves on and steps further “back” in search of another pair_..
    _.. But just before it does that check, all codes, including this new Function, at the last found [ , do a check to see if in fact the next character after the last found [ is a / , indicating that in fact the assumed start tag, [codeText], was in fact another end tag, [/Codetext_b]. Action is then taken should that be the case.
    At this point the codes are very different. The action taken is different
    In the previous code, it was assumed that in such an event, the first found “end tag” was a rouge text looking like an end tag , but invalid, and not matched to a start code tag. The first found “end tag” was then ignored, and another search made for a matching start tag to the second found end tag.
    This results in an error situation for a valid nested BB Code tags situations.
    The new code works therefore much differently.

    Main change 3):
    In the new code, this point is around lines
    430 – 460, Rem If [/ Then Oh dear time for a wonk.
    Recursion is the name given for the general technique which at this point is used. It is whereby within a routine an instruction is given to run the routine.
    ... In other words the Routine “Calls itself”.
    So what is all that about? :
    ‘_- I will tell you, Matey boy:
    Any Function or Sub routine we write, is just a set of instructions. Like a piece of paper which is a Print out of the typed code instructions. It tells VBA what to do when it is run or called. I does not really physically go along or through the code lines: We just find that easy to visualise, or “look at “ when “stepping” through to debug a code. The code is just a set of instructions that VBA understands.
    So imagine you are VBA and you are given a set of instructions ( on a piece of paper ) to do a job, (for example you are given a written copy of the instructions to read and follow).
    You start doing the instructions.
    Now, say, before you are finished, you are given a set of identical instructions and are told to do that by the boss. What do you do, ( apart from swear at him ) ?
    The logical progression is, ( and that is what VBA does ), it stops what it is doing, so like freezes the initial running through the instructions , and starts again with the new ( duplicate as it happens in the case of “recursion”) set of instructions.
    Once finished it goes back and picks up the first job where you / it left off. Within reason, there is no limit to how often you can do that in VBA. If a code makes a Function or Sub routine keep “Calling” itself , then it “stacks” up in order in a “waiting list” the stopped set of instructions. As each set of instructions is completed, the last are continued at the point where they were interrupted and “frozen”. That point is code line 450
    It follows, ( although may not be immediate obvious as the same names are used) that all variables used in each run of the Function within the function are unique to that run of the function so do not influence the values of the similarly named variables in the other Function runs. An exception here is our main full string, strBBCode. This is because we have deliberately chosen to carry it over By such a way as to indicate it should be Referenced to within each Function. So in this case, changes made in any Function run to strBBCode will be Reflected in the main ( unique ) variable, strBBCode, which is initially “held” / declared in the initial calling code.
    So what is all that to do with the main change to this code version ??
    ‘_- I will tell you, Matey boy:
    Initially the Function is called the first time by a small Sub routine which passes to the Function two things
    _(i) the variable strBBCode. It is indicated via the use of ByRef in the Function signature ( first ) line, that specifically that variable is to be Referenced. ( You may effectively take a variable “into” the Function ( ByRef ) , or alternatively a Value. If an actual value is given, then giving it ByRef is just the same as By Value. If you pass a Variable ByValue the value at the time of the Call in the variable will be taken, and that variable will become local to the Function and so any changes to it made in the function will not be reflected in the variable “held” in the initial calling routine ........ )
    _...(ii) a number .......Value... is given which will be the start position to work back from when looping backwards through the characters in strBBCode. For this first Call, that will be the length of / or character count of , strBBCode.

    The Function code then transgresses as described and very similar to the previous code. It can go to completion in one run should no end code tag be encountered after an initial one is found and before a start tag is found.
    ____If a second end tag in sequence is found the "recursion wonk" kicks in.....
    450 _____ Call LongWayOfDoingIt2ReCurseCyClops(strBBCode, BcrdSEnd)
    So _ If this line is done, the current run freezes. A New Function begins. This is instructed to Refer to the unique main string strBBCode “held” in the original Calling routine. As Value for the current position in the backward stepping search is this time not the main string strBBCode length, but rather the position of the end ] in the currently found second sequential end code tag.
    The only thing that is certain at this point is that the new Function run will immediately find this second end cote tag as its first end code tag. This is probably inefficient as it repeats some steps done. ( A more complicated Function could be envisaged to carry across an Offset to be applied to “jump” this search and pass the end code tag )
    With no more nested code tag pairs, the second Function will complete the entire string, other than the possible code tag pair search “frozen” in the first Function.
    When the first function resumes, the initial code tag pair search is completed.

    There are many other scenarios including a further nested code tags section the second function finds and results in a third Function starting. That third Function would complete all but the two pairs searches “frozen” . At completion of the third Function, the second and then the first Functions with their respective code tag pair search would be completed.

    Another scenario would be a double nesting such that there are three sequential end code tags. Once again a second followed by a third Function would be started. Once again, the third Function would complete all but the two pairs searches “frozen”. At completion of the third Function, the second and then the first Functions with their respective code tag pair search would be completed.

    One can imaging many more scenarios

    One common factor is that all but the final function will be searching through the replaced replacement characters. This probably makes the code a bit inefficient

    Final usage of Function
    Initial code to Call the Function for the first time. ( The function may Call itself one or more times further )
    The Function will not run itself.
    It needs to be Called with the initial parameters passed, the main string, strBBCode, along initially with the length of that string as the start point from which to step back.
    A routine is needed for that.
    Additionally, once the initial Function run , ( which is set off by this routine ) is finished, we will have the original string, strBBCode , returned in a modified form with the replacement character in place of all found code tags. These need to be removed, which can be easily achieved by replacing them with zero length strings.
    An example code is given in the next post.

    A few minor last thoughts..
    This second solution for manipulating a long string text does not require stepping backwards. It was simply developed on from the last code. That code was easier to do backwards as in the code parts were deleted whilst stepping through the string: It was easier to deal with such a code in a backward loop, as things “behind me” are deleted. The problem with going forward is that “deleting in front of me” can require adjusting “where I am”, and the count to, or “final point of where I am going to”. – Think of it as you tripping up, or effecting where the end is, if you chop out the path in front of you: VBA can get messed up in Looping if you remove points in a progression that have not yet been considered.
    Another way of thinking about that:
    If I take bits out, then things shift back or down to fill the space. If I take things out in front of me, then by shifting back, things which I have not yet considered will change their position. This will likely mess up some order of progression.
    If I go backwards, and delete things behind me, then any order changes will only affect things which I have already considered. My original progression plan and order of things not yet considered is still valid.
    Last edited by DocAElstein; 02-27-2017 at 09:44 PM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

  2. #2
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,385
    Rep Power
    10

    German Telecom ( Deutsch Telekom FreeMail t-online.de ) Copy Paste HTML code work around

    German Telecom ( Deutsch Telekom ( Freemail t-online.de ) ) Copy Paste HTML code work around

    I had a problem for a long time when copying manually via the clipboard from Microsoft Word ( or from most other sources ) into my main Email Internet tab Browser Program , t-online.de ( German Telekom Free mail).
    The problem started suddenly, close to the time that some update/ changes were made to the Program a few years ago.
    The problem was that usually most formatting was lost, and only simple plain b/w text came into the browser.
    Previously, most formatting , such as text color, text fonts , test size etc. were maintained such that the final E mail main body as seen and sent, looked very similar to as the prepared message in the Word document. This maintaining of format was / is still the case when pasting manually into gmail and many other places. ( This conversion to simple b/w is usually only seen when pasting into very simple basic text reply windows which supported no formatting )
    Formatedtext.JPG ; https://imgur.com/A9Sq5Y1 PastedInGermanEMail https://imgur.com/CZRH5jj
    Formatedtext.JPGPastedInGermanEMail.JPG
    ( Here is the same after pasting into gmail: PastedIn gmail.Jpg https://imgur.com/CzqCJ7y )



    I noticed the issue in a different situation, and was able to do a simple workaround that spread some light on the issue.
    This post gives the background to the situation.
    The next post explains the workaround. ( The workaround by passes pasting into the German Email Reply/Editor Window, but the sent and received Email does not suffer from the problem of loss of formatting ).

    The issue in a different situation..- The situation
    I answered a Forum question here recently, ( http://www.excelfox.com/forum/showth...kbooks-at-once ), and a spin off was a further insight into the issue.
    The thread concerned automating sending of an Email with attachments using ( Excel ) VBA.
    The successful solution involved sending directly to any Email the complete protocols, messages, HTML code string etc.. etc.. that any Email program, such as Email Internet tab Browser Program , t-online.de , would in end effect “send” out along the internet. ( The final solution was not dependent on having any Email Program available or open. )

    The VBA Program to send Email solution:
    It was a completely independent “stand alone” solution: Part of the program “ took in “ the main body / main content of the message, that is to say what a user would normally manually type in and/ or paste in. ( As seen in the above screenshots )
    ( This main body is what I personally might prepare, for convenience, ( and for purposes of having a back up ) , in a Word document and then copy and paste manually across. That copied across would then be sent , and the Word document is then effectively my back up copy of the sent message )

    Supplying the main Email message body to the code:
    This main body can be supplied to/ given within the code
    either as…….
    _ a simple text string, like pseudo __ = “ Hello,” & vbCrLf &this is my message. “ __ , which would give a final message received like
    Hello,
    This is my message
    That text can also in code typically be supplied in a single String type variable in a typical code part like:
    Dim strText As String
    _ Let strText = "Hello," & vbCrLf & " this is my message"
    Code:
    Dim strText As String
    _  Let strText = "Hello," & vbCrLf & " this is my message"
    or………

    _ alternatively it could be given as HTML code supplied similarly in a long string variable. That string variable would contain a long string of all the HTML necessary to create text, table, pictures and all possible formatting. That HTML type code can usually be read by most “internet type” or general computer communication type software such as to be able to show a complete formatted page or pages just as one might see in an internet web site or a large Microsoft Word document containing all sorts of formatting including tables, pictures, etc.. etc.. ( I chose to use this second HTML string giving way). This sort of coding is the most common language, at least up until recent years, in computer communication generally.
    ( By the way htm, HTML ,XHTML, html are more or less the same – it is all to do with coding which mostly consists of ” tag pairs” made with pointy brackets https://www.youtube.com/watch?v=1gLh...D6F7E289625976 )
    Making/ writing the .htm code string
    If I was a fluent computer HTML expert then I could just write out the htm equivalent of the message with formatting that I wanted to send by Email. I am not, and I don’t need to be: There are many ways to get the code, such as free converters on the internet which give the code if you paste in what you finally want into a window. ( All software I have tried have not suffered from loosing the format when I paste in to their window )
    But something even more convenient is available as standard with Microsoft Word:
    A simple practical solution was found to be to take advantage of the possibility of saving a normal Word ( file, normally saved with the extension .docx ) , with a file extension of .htm
    SaveAs Word.JPG Save As Word doc to htm.JPG https://imgur.com/h7XFAQX https://imgur.com/vhRE9CC
    This somehow saves the document primarily in some version of HTML coding language. ( I have no idea what it normally does with the .docx extension – probably a trade secret ). A small amount of coding was then all that was necessary to convert that .htm file into a single text string of the type required for the Email sending code with the option of supplying the main body in HTML format. ( That coding is a line like, pseudo _ strText = GetTheFileAsATextStreamandReadItAll_ )

    HTML is one of the main languages used in internet communication, and most internet browsers and Email programs use this. ( In the case of the first simple test string option, ( = “ Hello,” & vbCrLf &this is my message. “ ) , that given text string would probably be converted initially by some software into HTML coding before being further used . ( Hence it is more efficient to use the htm option in the first place )

    The long HTML string is rather difficult to “see” in its single string form as it is literally an extremely long sting text with pointy bracket HTML code. To a first approximation, this long string of information forms the bulk of what is actually “sent down the internet line”.
    No programmer could ever examine easily such a long string of coding. The coding is therefore organised neatly with things like the _ vbCrLf _ used in simple text strings to give a new line.
    Because of this last point, if you open such a HTML file with a simple text editor then you see the coding neatly laid out.
    For example, this is a screen shot of a simple Word document, which I made and then saved as .htm:
    ProMessageTelekom.JPG : https://imgur.com/zn3BGWj
    ProMessageTelekom.JPG
    “ProMessageTelekom.docx” : https://app.box.com/s/pumcahipuhjbl59ka7lb3qv8i682kcwc
    “ProMessageTelekom.htm” : https://app.box.com/s/vfz0y102bikl9hrka6dlgqyotlrttlpi

    If I right click on the .htm File in the explorer window, then I can choose to open this file in a simple text editor , ( rather than by using Word, which may be the default, - but note always: You might find that by default it opens on your Internet browser, - that is because , as noted, that browser software has as its main job reading HTML coding and converting it into the text , pictures, tables etc. that you can “see” )
    OpenProMessageHTMLWithTextEditor.JPG : https://imgur.com/4zev9Kv
    OpenProMessageHTMLWithTextEditor.jpg
    Opening the file in a text editor will give you ( towards the end ) the actual coding relevant specifically to “making” that seen text. The relevant part is in between the “pointy bracket code tag pair” named _ div class=WordSection1 ___ /div __ That section is all that I am interested in: All the other stuff is I expect a lot of stuff specific to a Word Document or maybe even some other complicated stuff. I don’t know
    ProMessageHTMLInTextEditor.JPG : https://imgur.com/eTUd17q
    ProMessageHTMLInTextEditor.jpg

    Last part of HTML code for File “ProMessageTelekom.htm” :
    See here:
    http://www.excelfox.com/forum/showth...0525#post10525




    Using code instead of Email Window to send Email ( with attachments )
    The codes for doing this are described from here: http://www.excelfox.com/forum/showth...0518#post10518
    The end result is , simplified, as follows:
    The .htm file is “sent” by the code along the internet line as a HTML code string
    rather than
    pasting into the Email Editor and hitting the send button manually

    The German Telekom Email Editor / Email Program is not used by this particular code . ( that step is effectively bypassed). So, the issue of the format loss occurring when pasting into the German Telekom Email Editor / Email Program is not present

    However: The received Email in German Telekom suffered a similar problem.
    Using the same Word file example again:
    This was the File used to produce the HTML code string to send
    ProMessageTelekom.JPG : https://imgur.com/zn3BGWj
    This came on as expected in most places, for example in gmail:
    ProMessageArrivedAt gmail UsingCodeToSend.jpg : ProMessageTelekom.JPG : : https://imgur.com/u57kRD7



    But.
    .. The same sent to a German Telekom t-onlone.de address came on with a similar format loss problem to that experienced when pasting into the German Telekom Email Editor / Email Program
    ProMessageRecievedAT tOnLinede UsingCodeToSend.JPG : https://imgur.com/h4wJVXd



    _.______________________



    So that this post was in way of an introduction.

    In the next post is the bit relevant to the issue with pasting into a German Telekom Email Window..
    Last edited by DocAElstein; 03-01-2018 at 10:33 PM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

Posting Permissions

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