.NET 3.x Создание пользовательской функции в MathCAD 11 - Visual Basic .NET
Формулировка задачи:
Доброго и
уни
, пытаюсь написать простенькую функцию для mathcad 11 (более шустрая версия) почитав статью на хабре и примеры , функция чтения файлавызываю ее и - ошибка - "general protection error"
наверно все объявления переменных в вункции
NumericEvaluation
кроме первой - ошибочны но и конвертировать в TComplex не получается - невозможно преобразовать string в TComplexРешение задачи: «.NET 3.x Создание пользовательской функции в MathCAD 11»
textual
Листинг программы
Imports System.Reflection
Imports NetEFI
Imports System.IO
Public Class readfile
Implements IFunction
Private _info As FunctionInfo
Public ReadOnly Property Info() As FunctionInfo Implements IFunction.Info
Get
Return _info
End Get
End Property
Public Sub New()
_info = New FunctionInfo("readfile", "filepatch", "dilimited", _
New Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath, _
GetType(String), _
New Type() {GetType(String), GetType(String), GetType(TComplex), GetType(TComplex), GetType(TComplex)}) ', GetType(TComplex(,))
End Sub
Public Function GetFunctionInfo(ByVal lang As String) As FunctionInfo Implements IFunction.GetFunctionInfo
Return Info
End Function
Private Function readf(dfile As String, dilimited As String, n As Integer, z As Integer, x As Integer) As String
On Error Resume Next
If File.Exists(dfile) Then
Dim sReader As New System.IO.StreamReader(dfile, System.Text.Encoding.UTF8)
Dim sArray As String()
Dim I As Integer = 0
Do While sReader.Peek >= 0
ReDim Preserve sArray(I)
sArray(I) = sReader.ReadLine
I += 1
Loop
If Not IsNothing(sArray) Then
Dim rows As Integer = sArray.Length - 1
Dim cols As Integer = sArray(0).Split(dilimited).Length - 1
If n = 1 Then
readf = rows.ToString
rows = Nothing
ElseIf n = 2 Then
readf = cols.ToString
cols = Nothing
ElseIf n = 3 Then
Dim _array As String()
Dim array(rows, cols) As String
For K As Integer = 0 To rows
For J As Integer = 0 To cols
_array = sArray(K).Split(New Char() {dilimited})
array(K, J) = _array(J)
Next
Next
readf = array(z, x)
Erase array
Erase _array
End If
Else
readf = "null"
End If
Erase sArray
sReader.Close()
Else
readf = "error file patch"
End If
End Function
Public Function NumericEvaluation(ByVal args As Object(), ByRef result As Object) As Boolean Implements IFunction.NumericEvaluation
Dim dfile = DirectCast(args(0), [String])
Dim dilimited = DirectCast(args(1), [String])
Dim n = CInt(DirectCast(args(2), TComplex).Real)
Dim z As Integer = CInt(DirectCast(args(3), TComplex).Real)
Dim x As Integer = CInt(DirectCast(args(4), TComplex).Real)
result = readf(dfile, dilimited, n, z, x)
End Function
End Class