Visual Basic - Maple Help

Online Help

All Products    Maple    MapleSim


CodeGeneration

  

VisualBasic

  

translate Maple code to Visual Basic code

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

VisualBasic(x, cgopts)

Parameters

x

-

expression, list, rtable, procedure or module

cgopts

-

(optional) one or more CodeGeneration options

Description

• 

The VisualBasic command translates Maple code to Visual Basic code.

  

- If the parameter x is an algebraic expression, then a Visual Basic statement assigning the expression to a variable is generated.

  

- If x is a list, Maple Array or rtable of algebraic expressions, then a sequence of Visual Basic statements assigning the elements to a Visual Basic array is produced. Only the initialized elements of the rtable or Maple Array are translated.

  

- If x is a list of equations nm=expr where nm is a name and expr is an algebraic expression, this is understood to mean a sequence of assignment statements.  In this case, the equivalent sequence of Visual Basic assignment statements is generated.

  

- If x is a procedure, then a Visual Basic module is generated containing a function equivalent to the procedure, along with any necessary import statements.

  

- If x is a module, then a Visual Basic module is generated, as described on the VisualBasicDetails help page.

• 

The parameter cgopts may include one or more CodeGeneration options, as described in CodeGenerationOptions.

• 

For more information about how the CodeGeneration package translates Maple code to other languages, see Translation Details. For more information about translation to VisualBasic in particular, see VisualBasicDetails.

Examples

For a description of the options used in the following examples, see CodeGenerationOptions.

withCodeGeneration:

Translate a simple expression and assign to the name ``w'' in the target code.

VisualBasicx+yz2xz,resultname=w

w = -2 * x * z + y * z + x

Translate a list and assign to an array with name ``w'' in the target code.

VisualBasicx,2y,5,z,resultname=w

w(0,0) = x
w(0,1) = 2 * y
w(1,0) = 5
w(1,1) = z

Translate a computation sequence.  Optimize the input first.

css=1.0+x,t=lnsexpx,r=expx+xt:

VisualBasiccs,optimize

s = 0.10E1 + x
t1 = Log(s)
t2 = Exp(-x)
t = t2 * t1
r = x * t + t2

Declare that x is a float and y is an integer.  Return the result in a string.

sVisualBasicx+y+1,declare=x::float,y::'integer',output=string

scg = x + CDbl(y) + 0.1E1

(1)

Translate a procedure.  Assume that all untyped variables have type integer.

f := proc(x, y, z) return x*y-y*z+x*z; end proc:

VisualBasicf,defaulttype=integer

Public Module CodeGenerationModule
  Public Function f( _
    ByVal x As Integer, _
    ByVal y As Integer, _
    ByVal z As Integer) As Integer
    Return y * x - y * z + x * z
  End Function
End Module

Translate a procedure containing an implicit return.  A new variable is created to hold the return value.

f := proc(n)
  local x, i;
  x := 0.0;
  for i to n do
    x := x + i;
  end do;
end proc:

VisualBasicf

Public Module CodeGenerationModule
  Public Function f(ByVal n As Integer) As Double
    Dim x As Double
    Dim i As Integer
    Dim cgret As Double
    x = 0.0E0
    For i = 1 To n
      x = x + CDbl(i)
      cgret = x
    Next
    Return cgret
  End Function
End Module

Translate a procedure accepting an Array as a parameter.  Note that the indices are renumbered so that the Visual Basic array starts at index 0.

f := proc(x::Array(numeric, 5..7))
  return x[5]+x[6]+x[7];
end proc:

VisualBasicf

Public Module CodeGenerationModule
  Public Function f(ByVal x() As Double) As Double
    Return x(0) + x(1) + x(2)
  End Function
End Module

Translate a module with one exported and one local procedure.

m := module() export p; local q;
    p := proc(x,y) if y>0 then trunc(x); else ceil(x); end if; end proc:
    q := proc(x) sin(x)^2; end proc:
end module:

VisualBasicm,resultname=t0

Imports System.Math

Public Module m
  Public Function p(ByVal x As Double, ByVal y As Integer) As Integer
    If (0 < y) Then
      Return Fix(x)
    Else
      Return Ceiling(x)
    End If
  End Function
  Private Function q(ByVal x As Double) As Double
    Return Pow(Sin(x), 0.2E1)
  End Function
End Module

Translate a linear combination of hyperbolic trigonometric functions.

VisualBasic2coshx7tanhx

cg0 = 0.2E1 * Cosh(x) - 0.7E1 * Tanh(x)

Translate a procedure with no return value containing a printf statement.

f := proc(a::integer, p::integer)
  printf("The integer remainder of %d divided by %d is: %d\n", a, p, irem(a, p));
end proc:

VisualBasicf

Public Module CodeGenerationModule
  Public Sub f(ByVal a As Integer, ByVal p As Integer)
    System.Console.WriteLine("The integer remainder of " & a & " divided by " & p & " is: " & a Mod p)
  End Sub
End Module

See Also

CodeGeneration

CodeGenerationOptions

trademark

Translation Details

VisualBasicDetails