How simply to do "try-except" in NAV

Yaroslav_Gaponov
Member Posts: 158
Hi
I propose simple method for catch an errors in NAV.
Need such Automation:
VBScript Automation 'Microsoft Script Control 1.0'.ScriptControl
Example:
IF NOT ISCLEAR(VBScript) THEN
CLEAR(VBScript);
CREATE(VBScript);
VBScript.Language := 'VBScript';
Source := STRSUBSTNO('' +
'Function TryExceptMethod' + '%1%1' +
' On Error Resume Next' + '%1%1' +
' TryExceptMethod = FALSE' + '%1%1' +
' a = 10 %2 0' + '%1%1' + // except!!!
' IF Err.Number = 0 THEN' + '%1%1' +
' TryExceptMethod = TRUE' + '%1%1' +
' END IF' + '%1%1' +
'End Function','#','\')
;
WHILE STRPOS(Source,'##') > 0 DO BEGIN
Source[STRPOS(Source,'#')] := 13;
Source[STRPOS(Source,'#')] := 10;
END;
VBScript.AllowUI := FALSE;
VBScript.AddCode(Source);
MESSAGE('Result = %1',VBScript.Eval('TryExceptMethod'));
CLEAR(VBScript);
The kernel of the problem:
Use a VBScript (JScript) Automation and command "On Error Resume Next".
p.s. you can pass a variables from NAV to VBScript like Automation etc... so VBScript.AddObject('objConnection',ADOConnection);
and execute all methods it from script.
Goog luck!!!
I propose simple method for catch an errors in NAV.
Need such Automation:
VBScript Automation 'Microsoft Script Control 1.0'.ScriptControl
Example:
IF NOT ISCLEAR(VBScript) THEN
CLEAR(VBScript);
CREATE(VBScript);
VBScript.Language := 'VBScript';
Source := STRSUBSTNO('' +
'Function TryExceptMethod' + '%1%1' +
' On Error Resume Next' + '%1%1' +
' TryExceptMethod = FALSE' + '%1%1' +
' a = 10 %2 0' + '%1%1' + // except!!!
' IF Err.Number = 0 THEN' + '%1%1' +
' TryExceptMethod = TRUE' + '%1%1' +
' END IF' + '%1%1' +
'End Function','#','\')
;
WHILE STRPOS(Source,'##') > 0 DO BEGIN
Source[STRPOS(Source,'#')] := 13;
Source[STRPOS(Source,'#')] := 10;
END;
VBScript.AllowUI := FALSE;
VBScript.AddCode(Source);
MESSAGE('Result = %1',VBScript.Eval('TryExceptMethod'));
CLEAR(VBScript);
The kernel of the problem:
Use a VBScript (JScript) Automation and command "On Error Resume Next".
p.s. you can pass a variables from NAV to VBScript like Automation etc... so VBScript.AddObject('objConnection',ADOConnection);
and execute all methods it from script.
Goog luck!!!
0
Comments
-
-
Hi
I use like solution for catch an errors for work with ADO Automation when I need to get a list databases on server. If some database in suspend status than user show an errors.
So if you need catch an errors for some Automation you can pass it as variable to script and execute the problem method.0 -
Hi
I have Compiled the code U have provided.
Fine But I did't able to understand How the 'Add Object' thing works.
I have added for ADO connection the Automation Variable 'Microsoft Active X Control Object Library 2.7'.
Can you Plz Explain How we able to track errors with this code.
Regards
Kiran.Hi0 -
Hi
I think all clear in this example.
CREATE(objConnection);
objConnection.[SOME_PARAMETERS] := [SOME_VALUES]
...
VBScript.AddObject('objConnectionXXX',objConnection);
...
Source := STRSUBSTNO('' +
'Function Test' + '%1%1' +
' Test = FALSE' + '%1%1' +
' On Error Resume Next' + '%1%1' +
' objConnectionXXX.[SOME_METHOD_FOR_EXAMPLE]' + '%1%1' +
' IF Err.Number = 0 THEN' + '%1%1' +
' Test = TRUE' + '%1%1' +
' END IF' + '%1%1' +
'End Function','#')
;
...0 -
=D> =D> =D> =D>
I just want to say you are a very clever guy Yaroslav!
Thank you for sharing!Why don't you try my compare tool?
http://www.mibuso.com/dlinfo.asp?FileID=11230
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions