Problem with AddDefinition

Problem with AddDefinition - Сообщения

#1 Опубликовано: 18.08.2013 10:41:53
Edward Ulle

Edward Ulle

20 сообщений из 182 понравились пользователям.

Группа: Moderator

I was resurrecting my WizFunctions for use with the newer version of SMath Studio and code that used to work now doesn't.

The problem seems to be with Store.AddDefinition. Possible causes are Definition.IsFunction has no object reference but is ReadOnly so no way to set it. Or AddDefinition variables() needs to be initialized and I don't have a clue to what.

Any suggestions would be appreciated. Thanks.



[Moderator] Moved.
Ed
#2 Опубликовано: 18.08.2013 10:57:06
Davide Carpi

Davide Carpi

1416 сообщений из 2873 понравились пользователям.

Группа: Moderator

Hi TheWizEd

Here and here you can see some updated store.AddDefinition examples


Best regards,

Davide
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#3 Опубликовано: 18.08.2013 18:02:32
Edward Ulle

Edward Ulle

20 сообщений из 182 понравились пользователям.

Группа: Moderator

w3b5urf3r

I looked at your examples and at least now it doesn't crash but it's not storing the variable. What am i doing wrong? Its in "zsival(vname,value)". My idea is to be able to set variables from a source other than SMath Studio, such as a file.

    Public Function ExpressionEvaluation(root As SMath.Manager.Term, args()() As SMath.Manager.Term, ByRef context As SMath.Math.Store, ByRef result() As SMath.Manager.Term) As Boolean Implements SMath.Math.IPluginLowLevelEvaluation.ExpressionEvaluation
        Dim bResult As Boolean
        Dim sValue As String
        Dim dTerms As Term()
        Dim tTerms(0) As Term
        Dim answer As New List(Of Term)
        Dim i As Integer
        Dim j As Integer

        bResult = False
        sValue = ""

        If root.Type = TermType.Function And root.Text = "ztest" Then
            For i = args.GetLowerBound(0) To args.GetUpperBound(0)
                sValue = sValue + "i=" + Str(i) + ": "
                For j = args(i).GetLowerBound(0) To args(i).GetUpperBound(0)
                    sValue = sValue + " j=" + Str(j) + ": <" + args(i)(j).ToString + ">"
                Next
                dTerms = Decision.Preprocessing(args(i), context)
                sValue = sValue + vbCrLf + "i=" + Str(i) + ": "
                sValue = sValue + ListTerms(dTerms)
            Next
            MsgBox(sValue)
            answer.AddRange(Converter.ToTerms("1")
            result = answer.ToArray()
            bResult = True
        ElseIf root.Type = TermType.Function And root.Text = "zsival" Then
            dTerms = Decision.Preprocessing(args(1), context)
            MsgBox(ListTerms(dTerms))
            context.AddDefinition(args(0)(0).ToString, dTerms, tTerms)
            answer.AddRange(dTerms)
            result = answer.ToArray()
            bResult = True
        End If

        Return bResult

    End Function
Ed
#4 Опубликовано: 18.08.2013 20:34:50
Davide Carpi

Davide Carpi

1416 сообщений из 2873 понравились пользователям.

Группа: Moderator

try using:

Dim tTerms(-1) As Term

instead of:

Dim tTerms(0) As Term
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
1 пользователям понравился этот пост
Edward Ulle 18.08.2013 23:47:00
#5 Опубликовано: 18.08.2013 23:46:24
Edward Ulle

Edward Ulle

20 сообщений из 182 понравились пользователям.

Группа: Moderator

w3b5urf3r

That worked. Thanks much.
Ed
#6 Опубликовано: 19.08.2013 04:37:50
Davide Carpi

Davide Carpi

1416 сообщений из 2873 понравились пользователям.

Группа: Moderator

You're welcome, I'm glad to see you back in action


Best regards,

Davide
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#7 Опубликовано: 19.08.2013 23:58:51
Edward Ulle

Edward Ulle

20 сообщений из 182 понравились пользователям.

Группа: Moderator

Not sure if it matters but I made some minor changes to my code so an instance of the empty Term array was created instead of using the local variable array.

Replaced

        Dim tTerms(-1) As Term

with
      
        Dim tTerms As Term()
        tTerms = New Term() {}
        context.AddDefinition(args(0)(0).ToString, dTerms, tTerms)
Ed
1 пользователям понравился этот пост
Davide Carpi 20.08.2013 04:38:00
  • Новые сообщения Новые сообщения
  • Нет новых сообщений Нет новых сообщений