PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
The 1001 questions about vbRichClient5 (2019-06-12) - Page 3-VBForums
Page 3 of 3 FirstFirst 123
Results 81 to 92 of 92

Thread: The 1001 questions about vbRichClient5 (2019-06-12)

  1. #81
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,235

    Re: The 1001 questions about vbRichClient5 (2019-05-09)

    Quote Originally Posted by jpbro View Post
    Olaf - thank you very much for the clarifications re: cThreadHandler, very informative.

    I just tried your threaded cActiveScript approach on Windows 10.1809 and it worked flawlessly when compiled, but I get the following error on Terminate in the IDE (maybe this is normal in the IDE?):

    Code:
    Run-time error '453':
    
    Error Calling: Run()
    ThreadError: Can't find DLL entry point AtlAxWinTerm in atl
    Ah - did receive that error as well yesterday, and fixed it in the RC5-sources already ...
    (AtlAxWinTerm is an inline-function and not a public export in the atl.dll)

    What if you replace (in cScriptThread Class_Initialize) a new Cleanup-Script:
    Code:
          .Add "Sub Cleanup()" 'needed and called shortly before Thread-Termination
          .Add "  On Error Resume Next"
          .Add "    New_c.CleanupRichClientDll"
          .Add "  If Err Then Err.Clear"
          .Add "End Sub"
    Does that help in IDE-mode?

    Olaf

  2. #82
    New Member
    Join Date
    May 2018
    Posts
    11

    Re: The 1001 questions about vbRichClient5 (2019-05-17)

    If Not TH. WaitForEmpty JobQueue (15) = True Then'over 15S automatically clears all

    TH. Cancel Execution

    Else



    End If

    If the thread executes for a long time, is the main program hung up and waited for 15S to execute again? If so, it is equivalent to blocking mode, which will affect the mouse click interface response. I used to use the following methods, there is no difference between the two methods, thank you.



    Dim tAddTickCount As Long, tTickCount As Long

    TAddTickCount = 15

    TTickCount = New_c.HPTimer



    Do

    New_c.SleepEx 10

    DoEvents

    If TH.WaitForEmpty JobQueue = True Then Exit Do

    If New_c.HPTimer - tTickCount > tAddTickCount Then

    TH. Cancel Execution

    Endif

    End If

    Loop Until TH.JobQueueCount < 1

  3. #83
    Frenzied Member
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    1,275

    Re: The 1001 questions about vbRichClient5 (2019-05-09)

    Quote Originally Posted by Schmidt View Post
    Does that help in IDE-mode?
    Unfortunately that change did not seem to help in IDE mode - not a big deal if it's fixed in RC5 already for the next update though.

  4. #84
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,235

    Re: The 1001 questions about vbRichClient5 (2019-05-09)

    Quote Originally Posted by jpbro View Post
    Unfortunately that change did not seem to help in IDE mode - not a big deal if it's fixed in RC5 already for the next update though.
    Just restored my older RC5-Binary from last week...
    and with the changed Class_Terminate below it works for me now in the IDE...
    (suppressing the unwanted error-bubbling from the TH.Cleanup-call)
    Code:
    Private Sub Class_Terminate()
      On Error Resume Next
        Set tmrState = Nothing
        CancelFlag = True
        If Not TH.WaitForEmptyJobQueue(10) Then TH.CancelExecution
        TH.CallSynchronous "Run", "Cleanup"
        Set TH = Nothing
      On Error GoTo 0
    End Sub
    The above should work with all older RC5-versions.

    Nevertheless I've uploaded a new RC5-Binary now to the usual place...

    Olaf

  5. #85
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,235

    Re: The 1001 questions about vbRichClient5 (2019-05-17)

    Quote Originally Posted by yinxiaodan View Post
    If Not TH. WaitForEmpty JobQueue (15) = True Then...
    You can also write the above this way:
    Code:
      'wait for max 15 seconds, then cancel the Job-Execution in case the wait-procedure was not successful (returned False)
      If TH.WaitForEmptyJobQueue(15) = False Then TH.CancelExecution
    And when written that way - it will do basically the same thing, you've tried to implement by hand in your follow-up code-snippet.

    The Function-Signature for cThreadHandler.WaitForEmptyJobQueue is this one:
    (as e.g. Intellisense will show you - but also the VB6-IDE-ObjectExplorer):
    Code:
    Public Function WaitForEmptyJobQueue(Optional ByVal WaitMaxSeconds As Double = 3) As Boolean
    Note, that the above contains an Optional Param which is named WaitMaxSeconds (with a default at 3seconds).
    The Max-part should tell you, that only in case the JobQueue will not fall back to zero within that time, it will wait "to the max".
    If the JobQueueCount reaches zero earlier than in the given WaitMaxSeconds-Param, the Function will return earlier of course (with True).

    As for "blocking the main-thread" - I'm not sure where you see a problem...
    Because normally you want your already running thread, to finish its job.
    And a Job is finished, when you receive the TH_MethodFinished-Event.

    Normally the WaitForEmptyJobQueue-call only comes into play, when you want to shutdown your App (with a potentially still running thread-job).

    HTH

    Olaf

  6. #86

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2012
    Posts
    1,546

    Qustion 020: Does RC5 support RegExp?

    Qustion 020: Does RC5 support RegExp?

    I'd to know if RC5 supports RegExp? Thanks!

  7. #87

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2012
    Posts
    1,546

    Qustion 021: Can cActiveScript execute JavaScript code?

    Qustion 021: Can cActiveScript execute JavaScript code?

    I'd to know if cActiveScript can execute JavaScript code, such as parseInt, ParseFloat, String.Replace and so on.

    In addition, what advantages does cActiveScript have over VBScript? Thanks.

  8. #88
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,235

    Re: The 1001 questions about vbRichClient5 (2019-05-26)

    Q#20: No ... (but via JScript + cActiveScript there's a workaround - see below)

    Q#21:
    - JavaScript is supported in two modes (first Lang-String-param of the New_c.ActiveScript-constructor)
    1) "JScript" (the old classic MS-JScript-interpreter, which works also on older systems)
    2) "JScript9" (the much faster JS-engine, which came on systems with IE9 and higher)

    cActiveScript implements the IActiveScripting interfaces directly - it is in many parts compatible to the MS-ScriptControl,
    but implements a few extra-things like EventBinding and others...

    New_c.ActiveScript() with no optional Params given will use the defaults and return a "VBScript"-Scripting-instance:
    - with the RC5 cConstructor and cCairo instances available directly within ScriptCode as usual via New_c and Cairo
    - with all VbRuntime Consts and Enums available in ScriptCode
    - with all RC5-Consts and Enums available in ScriptCode

    New_c.ActiveScript("JScript") does the same as the above (New_c and Cairo available in JScript-Code)
    New_c.ActiveScript("JScript9") ... dito - but with the JScript9 engine

    If one does not need RC5-Objects or VBRuntime+RC5-constants in JScript- or JScript9- mode (which is usually the case),
    the instancing lines should be: New_c.ActiveScript("JScript", False, False) or New_c.ActiveScript("JScript9", False, False) respectively...

    Here an example, which does RegEx-stuff using the JScript(9) engines:
    Code:
    Option Explicit
    
    Private WithEvents SC As cActiveScript, CO As Object
    
    Private Sub Form_Load()
      Set SC = New_c.ActiveScript("JScript", False, False)
     ' Set SC = New_c.ActiveScript("JScript9", False, False) '<- this should work on Vista+-machines as well
    
          SC.AddCode "function RegExReplace(s, pat, srepl) {" & vbCrLf & _
                     "    var re = new RegExp(pat, 'g')" & vbCrLf & _
                     "    return s.replace(re, srepl)" & vbCrLf & _
                     "}"
          SC.AddCode "function RegExMatch(s, pat) {" & vbCrLf & _
                     "    var re = new RegExp(pat, 'g')" & vbCrLf & _
                     "    return s.match(re)" & vbCrLf & _
                     "}"
      Set CO = SC.CodeObject 'calls work fastest, when we use the CodeObject
    End Sub
    
    'convenience-wrappers around (latebound) calls of the CodeObject
    Function RegExReplace(S As String, Pat As String, sRepl As String) As String
      RegExReplace = CO.RegExReplace(S, Pat, sRepl)
    End Function
    Function RegExMatch(S As String, Pat As String) As String
      RegExMatch = CO.RegExMatch(S, Pat)
    End Function
    
    Private Sub Form_Click()
      On Error Resume Next
        'replace all "special chars" and "all Number-Digits"
        Debug.Print RegExReplace("abc._*_+_?_^_$_{_}_(_)_|_[_\123xyz", "[.*+?^${}|()\\\[\]]|[0-9]", "")
        'switch words
        Debug.Print RegExReplace("John Doe", "(\w+)\s(\w+)", "$2, $1")
        
        Dim Match 'simple Word-Matcher
        For Each Match In Split(RegExMatch("John Doe", "(\w+)"), ",")
          Debug.Print Match
        Next
     
      If Err Then Debug.Print Err.Description
    End Sub
    
    Private Sub SC_error(Description As String, ByVal LineNr As Long, ByVal CharPos As Long)
      If Len(Description) Then Debug.Print "Error in Line: " & LineNr & "-Pos: " & CharPos & " -> " & Description
    End Sub
    HTH

    Olaf
    Last edited by Schmidt; May 26th, 2019 at 12:16 PM.

  9. #89

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2012
    Posts
    1,546

    Re: The 1001 questions about vbRichClient5 (2019-05-26)

    Hi Olaf. I tested your code and RC5.ActiveScript implements the RegExp operation very well, thank you very much.

    But JScript doesn't seem to support some JavaScript functions, for example: String.fromCodePoint

    I executed the following JavaScript code with ActiveScript but it didn't work:

    JavaScript Code:
    1. function escapeVal(str) {
    2.         return str.replace(/&#([0-9]+);/g, function (_, m0) {
    3.             return String.fromCodePoint(parseInt(m0, 10));
    4.         }).replace(/&#x([0-9a-f]+);/g, function (_, m0) {
    5.             return String.fromCodePoint(parseInt(m0, 16));
    6.         }).replace(/&amp;|&lt;|&gt;|&quot;|&apos;/g, function (_) {
    7.             switch (_) {
    8.                 case '&amp;': return '&';
    9.                 case '&lt;': return '<';
    10.                 case '&gt;': return '>';
    11.                 case '&quot;': return '"';
    12.                 case '&apos;': return '\'';
    13.             }
    14.             return _;
    15.         });
    16.     }

    RC5.ActiveScript prompts the following error message:

    Error in Line: 3-Pos: 9 -> Object does not support the "fromCodePoint" property or method
    Method 'escapeVal' of object 'JScriptTypeInfo' failed


    The test code is as follows:

    Code:
    Option Explicit
    
    Private WithEvents SC As cActiveScript, CO As Object
    
    Private Sub Form_Load()
      'Set SC = New_c.ActiveScript("JScript", False, False)
      Set SC = New_c.ActiveScript("JScript9", False, False) '<- this should work on Vista+-machines as well
    
      SC.AddCode GetCode_EscapeVal()
      
      Set CO = SC.CodeObject 'calls work fastest, when we use the CodeObject
    End Sub
    
    'convenience-wrappers around (latebound) calls of the CodeObject
    Private Function RegExEscapeVal(S As String) As String
      RegExEscapeVal = CO.escapeVal(S)
    End Function
    
    Private Function GetCode_EscapeVal() As String
        With New_c.StringBuilder
            .AppendNL "function escapeVal(str) {"
            .AppendNL "    return str.replace(/&#([0-9]+);/g, function (_, m0) {"
            .AppendNL "        return String.fromCodePoint(parseInt(m0, 10));"
            .AppendNL "    }).replace(/&#x([0-9a-f]+);/g, function (_, m0) {"
            .AppendNL "        return String.fromCodePoint(parseInt(m0, 16));"
            .AppendNL "    }).replace(/&amp;|&lt;|&gt;|&quot;|&apos;/g, function (_) {"
            .AppendNL "        switch (_) {"
            .AppendNL "            case '&amp;': return '&';"
            .AppendNL "            case '&lt;': return '<';"
            .AppendNL "            case '&gt;': return '>';"
            .AppendNL "            case '&quot;': return '" & Chr(34) & "';"
            .AppendNL "            case '&apos;': return '\'';"
            .AppendNL "        }"
            .AppendNL "        return _;"
            .AppendNL "    });"
            .AppendNL "}"
            GetCode_EscapeVal = .ToString
        End With
        
    End Function
    
    Private Sub Form_Click()
        Const TEST_STRING = "&#" & "72" & ";" & "&#" & "101" & ";" & "&#" & "108" & ";" & "&#" & "108" & ";" & "&#" & "111" & ";" & "&#" & "20320" & ";" & "&#" & "22909" & ";"
        
      On Error Resume Next
        
        MsgBox RegExEscapeVal(TEST_STRING)
     
      If Err Then Debug.Print Err.Description
    End Sub
    
    Private Sub SC_error(Description As String, ByVal LineNr As Long, ByVal CharPos As Long)
      If Len(Description) Then Debug.Print "Error in Line: " & LineNr & "-Pos: " & CharPos & " -> " & Description
    End Sub
    Last edited by dreammanor; May 26th, 2019 at 10:56 PM.

  10. #90
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,235

    Re: The 1001 questions about vbRichClient5 (2019-05-26)

    Quote Originally Posted by dreammanor View Post
    Hi Olaf. I tested your code and RC5.ActiveScript implements the RegExp operation very well, thank you very much.

    But JScript doesn't seem to support some JavaScript functions, for example: String.fromCodePoint
    Well, that's why so called PolyFills (just google the term) exists, which beam the js-Versions of older Browsers into the "new age"...

    Please make no mistake - even the newer (and quite fast) JScript9-engine is old (in comparison to V12 or Mozillas-JSengine).

    Though for the isolated case above, you can do manually, what Polyfills ensure on a "grander scale" within older Browsers...
    just add the missing Method to the global String-Object of the js-engine beforehand:

    Code:
          With New_c.StringBuilder
              .AppendNL "String.fromCodePoint = function(x){"
              .AppendNL "    var code, elements = [];"
              .AppendNL "    for (var i = 0; i < arguments.length; i++){"
              .AppendNL "      code = +arguments[i];"
              .AppendNL "      elements.push(code < 0x10000"
              .AppendNL "        ? String.fromCharCode(code)"
              .AppendNL "        : String.fromCharCode(((code -= 0x10000) >> 10) + 0xD800, code % 0x400 + 0xDC00)"
              .AppendNL "       );"
              .AppendNL "    } return elements.join('')"
              .AppendNL "}"
              SC.AddCode .ToString
          End With
    HTH

    Olaf

  11. #91

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2012
    Posts
    1,546

    Re: The 1001 questions about vbRichClient5 (2019-05-26)

    Excellent solution !

    I used to be reluctant to use VBScript and JScript because they don't support the latest JS functions and syntax. Now I can boldly use VBScript (JScript) and RC5.ActiveScript. Thank you very much, Olaf.

  12. #92

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2012
    Posts
    1,546

    Qustion 022: Can RC5.ActiveScript implement JavaScript debugging?

    Qustion 022: Can RC5.ActiveScript implement JavaScript debugging?

    Currently JavaScript debugging is mainly done in the browser, which is very inconvenient. Can RC5.ActiveScript add some features to debug JavaScript? E.g: AddBreakpoint, ClearBreakpoints, and debugging related events. Thanks.
    Last edited by dreammanor; Jun 12th, 2019 at 04:24 AM.

Page 3 of 3 FirstFirst 123

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width