Page 1 of 1

Different Processing of Escape Characters in Mod Harbour

PostPosted: Wed Jan 31, 2024 4:10 am
by Otto
Hello everyone,
I am working with Mod Harbour and have noticed that in my JavaScript code \\n causes a line break,
while \n leads to an error. Is this a known behavior in Mod Harbour, or could there be another reason for it?
Has anyone had similar experiences or can give me a tip on how to handle this?
Best regards,
Otto

Re: Different Processing of Escape Characters in Mod Harbour

PostPosted: Wed Jan 31, 2024 5:59 am
by Antonio Linares
Dear Otto,

Could you please provide a small code example to review it ?

thanks

Re: Different Processing of Escape Characters in Mod Harbour

PostPosted: Wed Jan 31, 2024 8:46 am
by Otto
Dear Antonio,
"\n" -> "\\n" OK


Here is my test code. If I change the line to:
keysString += key + ": " + value + "\\n";
it works fine.

If I run it with keysString += key + ": " + value + "\n"; in HTML, all works fine.

Best regards,
Otto


Code: Select all  Expand view

REQUEST DBFCDX
REQUEST DBFFPT

function main

TEMPLATE
 

<!DOCTYPE html>
<html lang="de">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Key Anzeiger</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
    <div class="container mt-5">
        <h2>oRequest Schlüssel Anzeiger</h2>
        <button id="showKeysBtn" class="btn btn-primary">Schlüssel anzeigen</button>
        <ul id="keysList" class="list-group mt-3">
        </ul>
    </div>

    <script>
    $(document).ready(function() {
        var oRequest = {
            "FILEXPLORE": "Wert1",
            "ANOTHERKEY": "Wert2",
            "YETANOTHERKEY": "Wert3"
            // Weitere Schlüssel...
        };
   
        $('#showKeysBtn').click(function() {
            var keysString = "";
            $.each(oRequest, function(key, value) {
                keysString += key + ": " + value + "\n";
            });
            alert(keysString);
        });
    });
   
    </script>

</body>
</html>




ENDTEXT



return

INIT PROCEDURE PrgInit
   
    SET CENTURY ON
    SET EPOCH TO YEAR(DATE())-98
   
    SET DELETED ON
    SET EXCLUSIVE OFF
   
    REQUEST HB_Lang_DE
   
    HB_LangSelect("DE")
   
    SET DATE TO GERMAN
   
    rddsetdefault( "DBFCDX" )
   
    EXTERN DESCEND
   
RETURN

//----------------------------------------------------------------------------//

 

Re: Different Processing of Escape Characters in Mod Harbour

PostPosted: Wed Jan 31, 2024 1:38 pm
by Ruth
Dear Otto,
I think \n leads to an error because the backslash is an escape character in javascript.
according to chatgpt :-) ... when used in a string, the \ expects to be followed by another character to form the escape sequence.
So \\n is needed in this case I suppose.
kind regards
ruth

Re: Different Processing of Escape Characters in Mod Harbour

PostPosted: Wed Jan 31, 2024 4:55 pm
by Otto
Dear Ruth,
the problem is that \n in JS works in a html file but not in a mod harblur prg file.

Please copy the HTML part into a HTML file and test.
Best regards,
Otto

Re: Different Processing of Escape Characters in Mod Harbour

PostPosted: Wed Jan 31, 2024 6:43 pm
by Ruth
...oh...yes...I see and I can confirm this...
next time I will also read the heading of the forum-post -> sorry :-)

kind regards
ruth