LotusScript 学习笔记1
一、简介
LotusScript 是基于Lotus应用平台的面向对象的脚本语言。
具有以下几个优点:
1.BASIC的扩展集
简单易学,学习过VB的用户,会很容易上手
2.跨平台
Windows,Macintosh, OS/2, UNIX, z/OS, and OS/400等平台都支持
3.面向对象
LotusScript 具有自定义的对象类,用户可以访问调用这些类。同时,这些类大部分是事件驱动的。
4.包含在Lotus software application中
可以通过编写Lotus Script来访问Lotus software application中的类库。
5.OLE支持
6.与其他语言的交互
formula,java,javascript
7.IDE(Integrated Development Environment)
LotusScript的IDE提供了创建,编辑,和debug 的功能,同时也可以浏览类的变量和属性信息。
8.LotusScript libraries
可以编写并且在Lotus应用程序和其他应用中使用。
9.可以通过LSXs 进行扩展
LSXs:Lotus Software Extensions,用户可以创建自己的类和对象。
二、脚本和声明的语法
声明的语法
1.一般一个功能语句是一行,其中包括LotusScript的关键字,操作,变量名等
2.空白行、缩进并不会产生影响,单词之间用空格隔开,多个空格无影响
3.一条声明尽量在一行之内,程序块的声明,需要换行时一般用_放在需要继续的一行的尾部。
4.一条语句结束一般直接换行,若是一行中有多个语句,用:隔开
5.注释一般是用'开始
例子
'One statement on one line
Print "One line"
'One statement on two lines; extra white space
Print "One" & _ 'Comment allowed here
"Two"
'Two statements on one line
Print "One" : Print "Two"
String的表示,可以用个"",||,{}.||中的字符可以包含多行。三种符号不可以嵌套。
如果想要将",|,{作为String的内容,写两次便可。例如:|A bar string with a bar || in it|
变量,常量,类型,类,函数,子函数或者熟悉的命名:
首字符必须为大写或者小写的字母;
必须是字母,数字或者_;
不区分大小写;
可以添加类型后缀(%, &, !, #, @, or $);
最大长度40;
三、数据类型,常量和变量
常用类型
Boolean,2bytes
Byte, 1bytes
Integer, 2bytes
Long, 4bytes
Single, 4bytes
Double, 8bytes
Currency,8bytes
String, 2bytes/character
数据结构
Array
List
Variant
用户自定义的数据结构和类。
数据类型转换
当我们在一个操作中遇到两个不同类型的number时,我们需要把他们转换成同一个类型。
一般我们选择转换成两个中高等级的类型。等级从低到高如下:
Byte,Integer, Long, Single, Double, Currency。
值传递时,数据类型若不是过程期待的类型时,LotusScript会尝试转换成需要的类型,转换过后值过大就会报错。
引用传递时,数据类型必须匹配函数的要求。
数据转换函数:CBool, CByte, CCur, CDat, CDbl, CInt, CLng, CSng, CStr, and CVar.
数据转换tips
$基本上可以讲任何数据转化为String
修复截断一个浮点数到整型总会变成零
int截断一个浮点数到整型值总会变小
DateValue把一个String的数据转化成date
DateNumber把一系列数字转化成date value
自动数据转换,隐式数据类型转换的情况:
给变量赋值的类型与变量的类型不同;
当数据操作超过变量类型的上线时,例如:
aVariantV = 32767
Print TypeName(aVariantV) ’ Output: INTEGER
aVariantV = aVariantV + 5
Print TypeName(aVariantV) ’ Output: LONG
并不是每次格式转换都会成功的,格式转换失败的话汇报相应的错误
Example 1
'This example illustrates the automatic conversion
'of decimal numbers to integers that happens when you perform
'integer division and when you assign a decimal number value
'to an integer variable.
Dim anInt As Integer
Dim aDouble As Double
'Do floating-point division.
anInt% = 12/7
Print anInt%
'Output: 2
aDouble# = 12/7
Print aDouble#
'Output: 1.71428571428571
'Do integer division.
anInt% = 12\7
Print anInt%
'Output: 1
aDouble# = 12\7
Print aDouble#
'Output: 1
'Do floating-point division.
anInt% = 12.5/2
Print anInt%
'Output: 6
aDouble# = 12.5/2
Print aDouble#
'Output: 6.25
'Do integer division.
anInt% = 12.5\2
Print anInt%
'Output: 6
aDouble# = 12.5\2
Print aDouble#
'Output: 6
本文介绍了LotusScript的基本概念和特性,包括其作为BASIC扩展集的易学性,跨平台支持,面向对象编程,以及在Lotus软件中的应用。此外,还详细讲解了LotusScript的语法,数据类型,常量和变量,以及数据转换的规则和技巧。

243

被折叠的 条评论
为什么被折叠?



