locked
vb .net function in BRE RRS feed

  • Question

  • Hello Every one,

    I am using business rule engine which will be later used in the web service. In this BRE:

    1. I am using .net assemblies as the schema

    2. I created few function in vb.net and C#

    Problem I am facing is that while testing, the functions in vb.net are not executed. Conditions with those functions are not evaluated.

    Same thing happened with C# but it works fine after adding "staticsupport" in Regedit.


    Sample vb.net function:

            Public Function CheckNumeric(ByVal strValue As String) As Boolean
                If IsNumeric(strValue) Then
                    Return True
                Else
                    Return False
                End If
            End Function

    Please help me with this issue. Thanks in Advance.

    Thanks & Regards,

    Vinay.

    Tuesday, January 6, 2015 3:18 PM

Answers

  • As this is a question, you should change the thread type to Question instead of Discussion.

    Public Shared Function CheckNumeric()

    'Shared' is the VB equivalent of C#'s 'static'.

    • Marked as answer by bvinay Wednesday, January 7, 2015 6:54 PM
    Wednesday, January 7, 2015 3:30 PM
    Moderator
  • Yes its been well described that to use static method from Helper class you need to update the registry something like below

    x86: HKLM_LOCAL_MACHINE\\SOFTWARE\Microsoft\BusinessRules\3.0\ x64: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\BusinessRules\3.0

    with REG_DWORD key named “StaticSupport“, with a value of "1" to the above registry path


    Now coming back to your issue VB does not support static keyword so your function declaration should be like below

     Public Shared Function CallRule(ByVal name As String) As UserAccount
    
         'code here
    
     End Function

    You can try some online converter available over net which can convert your C# code to equivalent VB code

    Thanks

    Abhishek

    • Marked as answer by bvinay Wednesday, January 7, 2015 6:54 PM
    Wednesday, January 7, 2015 6:35 PM

All replies

  • Please show us your error message?
    Wednesday, January 7, 2015 9:02 AM
  • There is no error message

    rule 1:  

    condition:

    BREVB.Functions.CheckNumeric(Application.get_RiskGrade) is equal to True

    applicant.get_income is not equal to 1000

    Action

    Applicant.Set_Income(1000)

    Update Applicant

    Rule 2:

    Applicant.get_Income is equal to 1000

    applicant.get_riskGrade is not equal to RG2

    Action:

    Applicant.Set_RiskGrade(RG2)

    Check Numeric Function is not evaluated below.

    RULE ENGINE TRACE for RULESET: sampleBre 1/7/2015 8:36:06 AM

    FACT ACTIVITY 1/7/2015 8:36:06 AM
    Rule Engine Instance Identifier: ccb24cc2-5370-433b-8c38-90d12399e724
    Ruleset Name: sampleBre
    Operation: Assert
    Object Type: BusinessModel.Applicant
    Object Instance Identifier: 30123063

    CONDITION EVALUATION TEST (MATCH) 1/7/2015 8:36:06 AM
    Rule Engine Instance Identifier: ccb24cc2-5370-433b-8c38-90d12399e724
    Ruleset Name: sampleBre
    Test Expression: BusinessModel.Applicant.get_Income != 1000
    Left Operand Value: 10000
    Right Operand Value: 1000
    Test Result: True

    CONDITION EVALUATION TEST (MATCH) 1/7/2015 8:36:06 AM
    Rule Engine Instance Identifier: ccb24cc2-5370-433b-8c38-90d12399e724
    Ruleset Name: sampleBre
    Test Expression: BusinessModel.Applicant.get_Income == 1000
    Left Operand Value: 10000
    Right Operand Value: 1000
    Test Result: False

    FACT ACTIVITY 1/7/2015 8:36:06 AM
    Rule Engine Instance Identifier: ccb24cc2-5370-433b-8c38-90d12399e724
    Ruleset Name: sampleBre
    Operation: Retract
    Object Type: BusinessModel.Applicant
    Object Instance Identifier: 30123063



    --------------------------------------------------------------------------------


    • Edited by bvinay Wednesday, January 7, 2015 1:42 PM
    Wednesday, January 7, 2015 1:41 PM
  • As this is a question, you should change the thread type to Question instead of Discussion.

    Public Shared Function CheckNumeric()

    'Shared' is the VB equivalent of C#'s 'static'.

    • Marked as answer by bvinay Wednesday, January 7, 2015 6:54 PM
    Wednesday, January 7, 2015 3:30 PM
    Moderator
  • Yes its been well described that to use static method from Helper class you need to update the registry something like below

    x86: HKLM_LOCAL_MACHINE\\SOFTWARE\Microsoft\BusinessRules\3.0\ x64: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\BusinessRules\3.0

    with REG_DWORD key named “StaticSupport“, with a value of "1" to the above registry path


    Now coming back to your issue VB does not support static keyword so your function declaration should be like below

     Public Shared Function CallRule(ByVal name As String) As UserAccount
    
         'code here
    
     End Function

    You can try some online converter available over net which can convert your C# code to equivalent VB code

    Thanks

    Abhishek

    • Marked as answer by bvinay Wednesday, January 7, 2015 6:54 PM
    Wednesday, January 7, 2015 6:35 PM
  • Thank you Johns-305.

    It worked.

    Wednesday, January 7, 2015 6:55 PM
  • Hello Abhishek, I already entered it in regedit. so answer was to use SHARED.

    Thanks for response.

    Wednesday, January 7, 2015 6:56 PM
  • Hi John, i have one more question:

    Does public sub functions work in BRE?(can we change by ref to byval as we cannot give input when it is ByRef)

            Public Sub setMbership(ByRef myPrd As MyPrd, ByVal value As Double)
                myPrd.Membership = value
            End Sub

    Please let me know.

    Thanks For the help.

    Thanks & Regards,

    Vinay.

    Tuesday, January 13, 2015 5:29 PM