New script example after Seraph version 4.0 _seraphzone

Source: Internet
Author: User
Tags arrays
In 4.0, the most important major changes are as follows:
-Allow arrays to be directly assigned to each other and allow arrays to be parameters of a function.
-Lets you call a function declared later in a function, that is, the function declaration has nothing to do with the calling relationship. Make indirect recursion possible.
-Allows global variables to be defined at the script location after the function is defined. You can also declare a global variable in this use script to make it more flexible.

Examples of these improvements are illustrated below
allows arrays to be directly assigned to each other and allows the array to become a function parameter.

Example 1, arrays are directly assigned to each other
Function Main
Dim arr1[10]
Arr1[1]=5
#将数组arr1整体COPY至arr2
Arr2=arr1
The value of #输出arr2 [1] should be 5
Print (Arr2[1])
End Function

Example 2, array as parameter

Function fx (arr1, ByRef arr2)
Print (Arr1[1])
#改变byref参数arr2中的某个元素的值
arr2[1]=10
End Function

Function Main
Dim arr1[10],arr2[10]
Arr1[1]=5
FX (ARR1, ARR2)
#输出arr2 [1] value. This value is changed in the FX function and should output 10
Print (Arr2[1])
End Function

allows you to call the function declared later in the function, that is, the function declaration has nothing to do with the calling relationship.
Cases

Function Main
FX ()
End Function

#函数fx声明在main函数之后, the same can be called
Function FX
Print ("Hello")
End Function

allows you to define a global variable in a script location after the function is defined.
Cases

Dim a
Function FX
#a与b都是全局变量. Even if B is defined later, it does not affect its being called by the function previously declared
Print (a)
Print (b)
End Function

Dim b

Function Main
A=1
b=2
FX ()
End Function

Skill
With these new improvements, it becomes more powerful to load other child scripts with use in the script.
We know that in any location of the script we can use
#USE the name of the foot
To load the contents of a script to the current position.
Previously, because the dim definition was allowed to be placed only before all function definitions, this made it difficult to put some functions that needed to use a custom global variable in a child script, especially when using multiple such scripts. After the 4.0 version, the problem was solved.

Cases:
Main script content:

Function FX
End Function

#use Utils.ser

Function Main
#访问在子脚本中定义的全局变量
A=1
#访问在子脚本中定义的函数
Myprint ()
End Function

Child Script Utils.ser content:
Dim a
function Myprint
Print (a)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.