magicdemoapp.vb
来自「matlab实用教程」· VB 代码 · 共 86 行
VB
86 行
' *******************************************************************************'' MagicDemoApp.vb'' This file is an example for using MATLAB COM component inside .NET Visual ' Basic application.'' Copyright 2001-2006 The MathWorks, Inc.'' *******************************************************************************Imports SystemImports MagicDemoCompNamespace MathWorks.Demo.MagicDemoApp ' <summary> ' The MagicDemoApp class computes a magic square of the user specified size. ' </summary> ' <remarks> ' args[0] - a positive integer representing the array size. ' </remarks> Class MagicDemoApp#Region " MAIN " ' <summary> ' The main entry point for the application. ' </summary> Shared Sub Main(ByVal args() As String) Dim arraySize As Integer Dim magic As MagicSquareClass = Nothing Try ' Get user specified command line arguments or set default If (0 <> args.Length) Then arraySize = System.Int32.Parse(args(0)) Else arraySize = 4 End If ' Create the magic square object magic = New MagicSquareClass ' Compute the magic square and print the result Dim nativeArray As Object = New Object magic.makesquare(1, nativeArray, arraySize) ' Convert the magic square array to a two dimensional native double array Console.WriteLine("{0}Magic square as native array:{1}", Chr(10), Chr(10)) If (nativeArray.GetType().IsArray) Then Dim myArray As System.Array = CType(nativeArray, System.Array) ' Display the array elements: For i As Integer = myArray.GetLowerBound(0) To myArray.GetUpperBound(0) For j As Integer = myArray.GetLowerBound(1) To myArray.GetUpperBound(1) Console.WriteLine("Element({0},{1})= {2}", i, j, myArray.GetValue(i, j)) Next j Next i End If Console.ReadLine() ' Wait for user to exit application Catch exception As System.Runtime.InteropServices.COMException Console.WriteLine("COM Error: {0}", exception) Catch exception As Exception Console.WriteLine("Error: {0}", exception) Finally ' Free the COM object If Not (magic Is Nothing) Then System.Runtime.InteropServices.Marshal.ReleaseComObject(magic) End If End Try End Sub#End Region End ClassEnd Namespace
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?