自己尝试翻译了B4A5.8的函数手册,主要是为了熟悉核心功能
核心
Bit
Bit是一个包含了与位运算有关函数的预定义对象(预定义指你不需要去定义)
例如:
Dim flags As Int flags = Bit.Or(100, 200)
事件:
无
成员:
And (N1 As Int, N2 As Int) As Int Not (N As Int) As Int Or (N1 As Int, N2 As Int) As Int ParseInt (Value As String, Radix As Int) As Int ShiftLeft (N As Int, Shift As Int) As Int ShiftRight (N As Int, Shift As Int) As Int ToBinaryString (N As Int) As String ToHexString (N As Int) As String ToOctalString (N As Int) As String UnsignedShiftRight (N As Int, Shift As Int) As Int Xor (N1 As Int, N2 As Int) As Int
成员详解
And (N1 As Int, N2 As Int) As Int
返回两个数的按位与运算结果
Not (N As Int) As Int
返回按位取反的结果
Or (N1 As Int, N2 As Int) As Int
返回两个数的按位或运算结果
ParseInt (Value As String, Radix As Int) As Int
按指定的进制返回对应的整数值,Radix介于2和36之间
ShiftLeft (N As Int, Shift As Int) As Int
按位左移Shift位
ShiftRight (N As Int, Shift As Int) As Int
按位右移Shift位(符号保持不变)
ToBinaryString (N As Int) As String
返回2进制字符串
ToHexString (N As Int) As String
返回16进制字符串
ToOctalString (N As Int) As String
返回8进制字符串
UnsignedShiftRight (N As Int, Shift As Int) As Int
按位右移Shift位(0补充右边的位)
Xor (N1 As Int, N2 As Int) As Int
返回按位异或的结果
DateTime
日期时间函数
DateTime也是一个预定义对象,他存储了从1970年1月1日到现在的毫秒数(Ticks)
函数DateTime.Date和函数DateTime.Time将毫秒数转换成字符串,你可以通过DateTime.Now获取当前的时间
例如
Dim now As Long
now = DateTime.Now
Msgbox("The date is: " & DateTime.Date(now) & CRLF & _
"The time is: " & DateTime.Time(now), "")
事件:
无
成员:
Add (Ticks As Long, Years As Int, Months As Int, Days As Int) As Long
Date (Ticks As Long) As String
DateFormat As String
DateParse (Date As String) As Long
GetDayOfMonth (Ticks As Long) As Int
GetDayOfWeek (Ticks As Long) As Int
GetDayOfYear (Ticks As Long) As Int
GetHour (Ticks As Long) As Int
GetMinute (Ticks As Long) As Int
GetMonth (Ticks As Long) As Int
GetSecond (Ticks As Long) As Int
GetYear (Ticks As Long) As Int
Now As Long [read only]
TicksPerDay As Long
TicksPerHour As Long
TicksPerMinute As Long
TicksPerSecond As Long
Time (Ticks As Long) As String
TimeFormat As String
TimeParse (Time As String) As Long
成员详解
Add (Ticks As Long, Years As Int, Months As Int, Days As Int) As Long
返回一个增加了指定年月日数值的新Ticks,如果想减少,参数送负数就可以了
例如
Dim Tomorrow As Long
Tomorrow = DateTime.Add(DateTime.Now, 0, 0, 1)
Log("Tomorrow date is: " & DateTime.Date(Tomorrow))
Date (Ticks As Long) As String
返回一个日期格式的字符串(按毫秒数Ticks存储)日期格式可以用DateFormat设置
例如
Log("Today is: " & DateTime.Date(DateTime.Now))
DateFormat As String
获取或设置日期的解析格式,支持模式参见formats。默认的格式为MM/dd/yyyy (例如04/23/2002).
DateParse (Date As String) As Long
将一个给定的日期字符串转换成一个Ticks,如果解析失败将会抛出一个异常
例如
Dim SomeTime As Long
SomeTime = DateTime.DateParse("02/23/2007")
GetDayOfMonth (Ticks As Long) As Int
返回Ticks中的月中的具体日数,1-31
GetDayOfWeek (Ticks As Long) As Int
返回Ticks中的具体星期数,1-7
GetDayOfYear (Ticks As Long) As Int
返回Ticks中的年中的具体日数,1-366
GetHour (Ticks As Long) As Int
返回Ticks中具体时数 ,0-23
GetMinute (Ticks As Long) As Int
返回Ticks中的具体分钟数,0-59
GetMonth (Ticks As Long) As Int
返回Ticks中的具体月份,1-12
GetSecond (Ticks As Long) As Int
返回Ticks中的具体秒数 ,0-59
GetYear (Ticks As Long) As Int
返回年份
Now As Long [只读]
返回代表当前时间的Ticks
TicksPerDay As Long
TicksPerHour As Long
TicksPerMinute As Long
TicksPerSecond As Long
Time (Ticks As Long) As String
返回代表当前时间的字符串,可以通过TimeFormat来指定格式
例如
Log("The time now is: " & DateTime.Date(DateTime.Now))
TimeFormat As String
按指定的格式获取或设置时间字符串
具体支持的格式可以查看formats
默认的格式是HH:mm:ss (例如23:45:12).
TimeParse (Time As String) As Long
根据给定的时间字符串,转换成相应的ticks值
Exception
用于抛出异常
你可以通过调用LastException来获取最后一个异常
例如
Try
Dim in As InputStream
in = File.OpenInput(File.DirInternal, "SomeMissingFile.txt")
'...
Catch
Log(LastException.Message)
End Try
If in.IsInitialized Then in.Close
事件:
无
成员:
IsInitialized As Boolean
Message As String [只读]
成员详解:
IsInitialized As Boolean
Message As String [只读]
Keywords
这里是一些内置的关键字
事件:
无
成员:
Abs (Number As Double) As Double
ACos (Value As Double) As DoubleACosD (Value As Double) As Double
Array
Asc (Char As Char) As Int
ASin (Value As Double) As Double
ASinD (Value As Double) As Double
ATan (Value As Double) As Double
ATanD (Value As Double) As Double
BytesToString (Data() As Byte, StartOffset As Int, Length As Int, CharSet As String)
As String
Catch
cE As Double
CharsToString (Chars() As Char, StartOffset As Int, Length As Int) As String
Chr (UnicodeValue As Int) As Char
Continue
Cos (Radians As Double) As Double
CosD (Degrees As Double) As Double
cPI As Double
CRLF As String
Density As Float
Dim
DipToCurrent (Length As Int) As Int
DoEvents
Exit
ExitApplication
False As Boolean
File As File
Floor (Number As Double) As Double
For
GetDeviceLayoutValues As LayoutValues
GetType (object As Object) As String
If
InputList (Items As List, Title As String, CheckedItem As Int) As Int
InputMultiList (Items As List, Title As String) As List
Is
IsBackgroundTaskRunning (ContainerObject As Object, TaskId As Int) As
Boolean
IsNumber (Text As String) As Boolean
LastException As Exception
LoadBitmap (Dir As String, FileName As String) As Bitmap
LoadBitmapSample (Dir As String, FileName As String, MaxWidth As Int,MaxHeight As Int) As Bitmap
Log (Message As String)
Logarithm (Number As Double, Base As Double) As Double
Max (Number1 As Double, Number2 As Double) As Double
Min (Number1 As Double, Number2 As Double) As Double
Msgbox (Message As String, Title As String)
Msgbox2 (Message As String, Title As String, Positive As String, Cancel As String,Negative As String, Icon As android.graphics.Bitmap) As Int
Not (Value As Boolean) As Boolean
Null As Object
NumberFormat (Number As Double, MinimumIntegers As Int, MaximumFractions As Int) As String
NumberFormat2 (Number As Double, MinimumIntegers As Int, MaximumFractions As Int, MinimumFractions As Int, GroupingUsed As Boolean) As String
PerXToCurrent (Percentage As Int) As Int
PerYToCurrent (Percentage As Int) As Int
Power (Base As Double, Exponent As Double) As Double
ProgressDialogHide
ProgressDialogShow (Text As String)
ProgressDialogShow2 (Text As String, Cancelable As Boolean)
QUOTE As String
Regex As Regex
Return
Rnd (Min As Int, Max As Int) As Int
Round (Number As Double) As Long
Round2 (Number As Double, DecimalPlaces As Int) As Double
Sender As Object
Sin (Radians As Double) As Double
SinD (Degrees As Double) As Double
Sqrt (Value As Double) As Double
StartActivity (Activity As Object)
Sub
TAB As String
Tan (Radians As Double) As Double
TanD (Degrees As Double) As Double
ToastMessageShow (Message As String, LongDuration As Boolean)
True As Boolean
Try
Type
Until
While
成员详解:
Abs (Number As Double) As Double
返回绝对值.
ACos (Value As Double) As Double
根据弧度返回角度.
ACosD (Value As Double) As Double
根据角度返回弧度.
Array
根据指定的类型,创建一个一维数组.
语法:
Array As type (值列表).
例如:
Dim Days() As String
Days = Array As String("Sunday", "Monday", ...)
Asc (Char As Char) As Int
返回字符或字符串首字符的unicode码
ASin (Value As Double) As Double
根据弧度返回角度.
ASinD (Value As Double) As Double
根据角度返回弧度.
ATan (Value As Double) As Double
根据弧度返回角度.
ATanD (Value As Double) As Double
根据角度返回弧度.
BytesToString (Data() As Byte, StartOffset As Int, Length As Int, CharSet As String) As String
将给定的字节数组转换成字符串
Data - 字节数组.
StartOffset - 需要转换的第一个字节.
Length - 转换的字节个数.
CharSet - 编码格式如ASCII,UTF8,GB2312.
例如:
Dim s As String
s = BytesToString(Buffer, 0, Buffer.Length, "UTF-8")
Catch
异常的抛出需要在一个try模块中,并由catch模块来捕获,调用LastException来获取捕获到的异常
语法:
Try
...
Catch
...
End Try
cE As Double
e (自然对数的底数) 常量.
CharsToString (Chars() As Char, StartOffset As Int, Length As Int) As String
将给定的字符数组转换成字符串
Chr (UnicodeValue As Int) As Char
根据给定的Unicode值获取对应的字符
Continue
停止执行当前的循环,转而执行下一个
Cos (Radians As Double) As Double
CosD (Degrees As Double) As Double
cPI As Double
PI 常量.
CRLF As String
换行,等同Chr(13).
Density As Float
返回设备的scale,由DPI/160确定
(DPI指每英寸的点数).
Dim
定义一个变量.
语法:
定义一个单独的变量:
Dim variable name [As type]
默认定义的是字符串.
定义多个变量. 所以的变量类型需一致.
Dim variable1, variable2, ..., [As type]
定义数组:
Dim variable(Rank1, Rank2, ...) [As type]
例如:
Dim Days(7) As String
定义0长度的数组时,括号内的值可以省略
DipToCurrent (Length As Int) As Int
Scales the value, which represents a specific length on a default density device (Density =
1.0),
to the current device.
For example, the following code will set the width value of this button to be the same
physical size
on all devices.
Button1.Width = DipToCurrent(100)
Note that a shorthand syntax for this method is available. Any number followed by the
string 'dip'
will be converted in the same manner (no spaces are allowed between the number and
'dip').
So the previous code is equivalent to:
Button1.Width = 100dip 'dip -> density independent pixel
DoEvents
DoEvents 可以在一个大的循环中允许程序响应事件
Exit
退出最内侧的循环
ExitApplication
立即结束程序退出进程
大部分的程序不应该使用ExitApplication来退出,而是调用Activity.Finish,由系统来判断什么时候结束进程。
False As Boolean
File As File
Files related methods.
Floor (Number As Double) As Double
返回比指定的数字小或相等的最大整数
For
语法:
For variable = value1 To value2 [Step interval]
...
Next
例如:
For i = 1 To 10
Log(i) '打印1-10 (包括10).
Next
GetDeviceLayoutValues As LayoutValues
返回设备的LayoutValues.
例如:
Log(GetDeviceLayoutValues)
GetType (object As Object) As String
返回变量的类型.
If
单行条件判断语句:
If condition Then true-statement [Else false-statement]
多行条件判断语句:
If condition Then
statement
Else If condition Then
statement
...
Else
statement
End If
InputList (Items As List, Title As String, CheckedItem As Int) As Int
显示一个输入选择列表框,选择一个列表将关闭此窗口
返回选择列表的索引号,如果用户点击了返回键将返回DialogResponse.Cancel
List - 显示的列表.
Title - 窗口标题.
CheckedItem - 默认的选择框,如果不想默认选择,可以设置为-1
InputMultiList (Items As List, Title As String) As List
显示一个可以多选的列表框,用户点击“OK”关闭
返回选中的List列表,如果用户点击了返回键,将返回一个空的List
Is
检查对象是否是指定的类型
例如:
For i = 0 To Activity.NumberOfItems - 1
If Activity.GetItem(i) Is Button Then
Dim b As Button
b = Activity.GetItem(i)
b.Color = Colors.Blue
End If
Next
IsBackgroundTaskRunning (ContainerObject As Object, TaskId As Int) As Boolean
检测一个容器中指定的id的sub是否在后头运行
IsNumber (Text As String) As Boolean
检测指定的字符串能否安全的转换为数字
LastException As Exception
获取最后捕捉的异常
LoadBitmap (Dir As String, FileName As String) As Bitmap
载入一个Bitmap
注意安卓的文件系统是区分大小写的
如果Bitmap图片太大,可能需要使用LoadBitmapSample
图片通常压缩存储,与实际文件大小无关
例如:
Activity.SetBackgroundImage(LoadBitmap(File.DirAssets, "SomeFile.jpg"))
LoadBitmapSample (Dir As String, FileName As String, MaxWidth As Int, MaxHeight As Int) As
Bitmap
载入bitmap.
如果bitmap的实际高度或宽度大于最大尺寸,将进行采样
这样在载入大图片时将会节省大量的内存
例如:
Activity.SetBackgroundImage(LoadBitmapSample(File.DirAssets, "SomeFile.jpg",
Activity.Width, Activity.Height))
Log (Message As String)
打印一条日志信息.
Message: 日志的信息.
Logarithm (Number As Double, Base As Double) As Double
Max (Number1 As Double, Number2 As Double) As Double
Returns the larger number between the two numbers.
Min (Number1 As Double, Number2 As Double) As Double
Returns the smaller number between the two numbers.
Msgbox (Message As String, Title As String)
显示一个message对话框
对话框将只显示一个ok按钮
Example:
Msgbox("Hello world", "This is the title")
Msgbox2 (Message As String, Title As String, Positive As String, Cancel As String, Negative As
String, Icon As android.graphics.Bitmap) As Int
显示一个message对话框
Message - 信息内容.
Title - 对话框标题.
Positive - "positive" 按钮需要显示的文本,如果不想显示这个按钮,设置为""
Cancel - "cancel" 按钮需要显示的文本,如果不想显示这个按钮,设置为""
Negative - "negative"按钮需要显示的文本,如果不想显示这个按钮,设置为""
Icon - 对话框中的图标. 如果不想显示这个按钮,设置为Null
返回DialogResponse的一个值.
例如:
Dim result As Int
result = Msgbox2("This is the message", "This is the title", "Good", "", "Bad",
LoadBitmap(File.DirAssets, "smiley.gif"))
If result = DialogResponse.Positive Then ...
Not (Value As Boolean) As Boolean
boolean值取反.
Null As Object
NumberFormat (Number As Double, MinimumIntegers As Int, MaximumFractions As Int) As
String
将指定的数值类型转换为字符串.
这个字符串将至少包含MinimumIntegers位整数部分和至多MaximumFractions位小数部分
例如:
Log(NumberFormat(12345.6789, 0, 2)) '"12,345.68"
Log(NumberFormat(1, 3 ,0)) '"001"
NumberFormat2 (Number As Double, MinimumIntegers As Int, MaximumFractions As Int,
MinimumFractions As Int, GroupingUsed As Boolean) As String
将指定的数值类型转换为字符串.
这个字符串将至少包含MinimumIntegers位整数部分和至多MaximumFractions位小数部分以及最少MinimumFractions 位小数部分
GroupingUsed - 决定是否每3位整数用,隔开.
例如:
Log(NumberFormat2(12345.67, 0, 3, 3, false)) '"12345.670"
PerXToCurrent (Percentage As Int) As Int
返回由宽度百分比决定的实际位置
例如:
Button1.Width = PerXToCurrent(50) 'Button1.Width = 50% * Activity.Width
一个简短的方式表示是在数字后面加上'%x'(中间无空格)
所以前面的代码等同于:
Button1.Width = 50%x
PerYToCurrent (Percentage As Int) As Int
返回由高度度百分比决定的实际位置
例如:
Button1.Height = PerYToCurrent(50) 'Button1.Height = 50% * Activity.Height
一个简短的方式表示是在数字后面加上'%y'(中间无空格)
所以前面的代码等同于:
Button1.Height = 50%y
Power (Base As Double, Exponent As Double) As Double
ProgressDialogHide
隐藏一个可见的进度框,如果无进度框则不作处理
ProgressDialogShow (Text As String)
显示一个进度对话框,包括一个进度图像和文本
不同于Msgbox 和InputList ,这段代码不会阻塞
你需要调用ProgressDialogHide 来移除此窗口
窗口在用户按下返回键时也将被移除
ProgressDialogShow2 (Text As String, Cancelable As Boolean)
显示一个进度对话框,包括一个进度图像和文本
不同于Msgbox 和InputList ,这段代码不会阻塞
你需要调用ProgressDialogHide 来移除此窗口
Cancelable -决定用户是否能通过返回键取消此对话框
QUOTE As String
引号. 等价于Chr(34).
Regex As Regex
正则表达式相关的方法
Return
从当前sub过程返回,并返回指定的值(可选择)
语法:
Return [value]
Rnd (Min As Int, Max As Int) As Int
返回Min(包含)和Max(不包含)之间的一个随机整数
Round (Number As Double) As Long
返回四舍五入的整数
Round2 (Number As Double, DecimalPlaces As Int) As Double
返回包含指定位数小数的四舍五入的数
Sender As Object
返回事件触发中的object 对象
只在事件过程中有效
Sin (Radians As Double) As Double
SinD (Degrees As Double) As Double
Sqrt (Value As Double) As Double
返回平方根
StartActivity (Activity As Object)
开启一个活动,或把它移动最前端
Activity 可以是一个Activity的标签字符串,或者一个实际的Activity对象
完成调用以后,当前的activity 将暂停,而目标activity将被重新开始
例如:
StartActivity (Activity2)
Sub
定义一个过程,包括参数和返回值(可选)
语法:
Sub name [(list of parameters)] [As return-type]
参数包括参数名和类型.
数组参数的维度不能包含在内.
例如:
Sub MySub (FirstName As String, LastName As String, Age As Int, OtherValues() As
Double) As Boolean
...
End Sub
在这个例子中OtherValues 是一个一维数组
返回类型如果是数组的话,需要括号
TAB As String
制表符.
Tan (Radians As Double) As Double
TanD (Degrees As Double) As Double
ToastMessageShow (Message As String, LongDuration As Boolean)
显示一个简短的消息并自动消失
Message - 需要显示的文本消息.
LongDuration - 如果设置为true,显示时间将会稍微长一点
True As Boolean
Try
Any exception thrown inside a try block will be caught in the catch block.
任何异常都需要在一个try模块中被抛出,并在catch模块中捕获
调用LastException 可以获取捕获的异常
语法:
Try
...
Catch
...
End Try
Type
定义一个结构体.
只能在Globals和Process_Globals中定义
语法:
Type type-name (field1, field2, ...)
Fields 包括名称和变量类型.
例如:
Type MyType (Name As String, Items(10) As Int)
Dim a, b As MyType
a.Items(2) = "very interesting item"
Until
循环执行,直到条件为真
语法:
Do Until condition
...
Loop
While
当条件为真时,循环执行
语法:
Do While condition
...
Loop
LayoutValues
Holds values related to the display.
与显示相关的数值
你可以通过GetDeviceLayoutValues获取当前显示界面相关的数值
例如:
Dim lv As LayoutValues
lv = GetDeviceLayoutValues
Log(lv) '调试打印
Activity.LoadLayout and Panel.LoadLayout
返回一个指定的LayoutValues 对象的布局值
事件:
无
成员:
Height As Int
Scale As Float
toString As String
Width As Int
成员描述:
Height As Int
显示的高度(pixels)
Scale As Float
The device scale value which is equal to 'dots per inch' / 160. For most devices the value
will be 1.0 or 1.5 (high resolution).
相较于标准分辨率的放大比例
toString As String
Width As Int
显示的宽度(pixels)
String
string在B4A中是不可变的,即你可以改变一个字符串变量的值,但是你不能改变字符串本身存储位置的值
所以SubString,Trim和ToLowerCase返回的是一个新的字符串,他们不会改变当前字符串的值
用途:
Dim s As String
s = "some text"
s = s.Replace("a", "b")
如果你需要一个可变的字符串,你可以使用StringBuilder
注意字符串常量也是字符串对象
Log(" some text ".Trim)
事件:
None
成员:
CharAt (Index As Int) As Char
CompareTo (Other As String) As Int
EndsWith (Suffix As String) As Boolean
EqualsIgnoreCase (other As String) As Boolean
GetBytes (Charset As String) As Byte()
IndexOf (SearchFor As String) As Int
IndexOf2 (SearchFor As String, Index As Int) As Int
Length As Int
Replace (Target As String, Replacement As String) As String
StartsWith (Prefix As String) As Boolean
SubString (BeginIndex As Int) As String
SubString2 (BeginIndex As Int, EndIndex As Int) As String
ToLowerCase As String
ToUpperCase As String
Trim As String
成员描述:
CharAt (Index As Int) As Char
返回给定索引的字符
CompareTo (Other As String) As Int
按字母顺序比较两个字符串
返回值小于0,表示当前字符串领先于Other字符串
返回值等于0,表示字符串相同
返回值大于0,表示当前字符串落后于Other字符串
注意大写字母领先于小写字母
例如:
"abc".CompareTo("da") ' < 0
"abc".CompareTo("Abc") ' > 0
"abc".CompareTo("abca")' < 0
EndsWith (Suffix As String) As Boolean
如果字符串是以指定的Suffix结尾,返回true
EqualsIgnoreCase (other As String) As Boolean
无视大小写,如果两个字符串相等,返回true
GetBytes (Charset As String) As Byte()
将字符串编码成一个Byte数组
例如:
Dim Data() As Byte
Data = "Some string".GetBytes("UTF8")
IndexOf (SearchFor As String) As Int
返回查找到的第一个匹配字符串的位置
如果未找到,返回-1
IndexOf2 (SearchFor As String, Index As Int) As Int
返回查找到的第一个匹配字符串的位置
从指定的索引开始查找
如果未找到,返回-1
Length As Int
返回字符串的长度
Replace (Target As String, Replacement As String) As String
返回一个覆盖了指定字符串的新字符串
StartsWith (Prefix As String) As Boolean
Returns true if this string starts with the given Prefix.
如果字符串以指定的字符串Prefix为前缀,返回true
SubString (BeginIndex As Int) As String
Returns a new string which is a substring of the original string.
返回一个从指定位置截取的新字符串
新的字符串包含指定的字符位置,直至字符串结尾
例如:
"012345".SubString(2) '返回 "2345"
SubString2 (BeginIndex As Int, EndIndex As Int) As String
返回一个从指定位置截取的新字符串
新的字符串包含指定的起始字符位置,不包含结尾字符位置
例如:
"012345".SubString2(2, 4) '返回 "23"
ToLowerCase As String
将字符串转换为小写
ToUpperCase As String
将字符串转换为大写
Trim As String
去掉字符串前端和尾端的空格
StringBuilder
StringBuilder是一个可变的字符串,不同于通常的字符串不可变
StringBuilder适合用于将多个字符串合并
下面的代码演示了通过StringBuilder提高性能
Dim start As Long
start = DateTime.Now
'Regular string
Dim s As String
For i = 1 To 5000
s = s & i
Next
Log(DateTime.Now - start)
'StringBuilder
start = DateTime.Now
Dim sb As StringBuilder
sb.Initialize
For i = 1 To 5000
sb.Append(i)
Next
Log(DateTime.Now - start)
在真实设备上,第一个循环需要20s,第二个循环少于10s
函数StringBuilder.ToString可以将对象转换为一个字符串
事件:
无
成员:
Append (Text As String) As StringBuilder
Initialize
Insert (Offset As Int, Text As String) As StringBuilder
IsInitialized As Boolean
Length As Int [只读]
Remove (StartOffset As Int, EndOffset As Int) As StringBuilder
ToString As String
成员描述:
Append (Text As String) As StringBuilder
在结尾连接指定的字符串
返回同一个对象,你可以多次调用
例如:
sb.Append("First line").Append(CRLF).Append("Second line")
Initialize
初始化对象
例如:
Dim sb As StringBuilder
sb.Initialize
sb.Append("The value is: ").Append(SomeOtherVariable).Append(CRLF)
Insert (Offset As Int, Text As String) As StringBuilder
从指定的位置插入字符串
IsInitialized As Boolean
Length As Int [只读]
返回对象中的字符数
Remove (StartOffset As Int, EndOffset As Int) As StringBuilder
移除指定的字符串
StartOffset - 第一个将被移除的字符索引.
EndOffset - 结尾字符索引. 这个字符不会被移除
ToString As String
将对象转换为string
Timer
定时器对象
推荐在一个时间较长的循环中使用Timer,因为他运行UI线程调度事件和消息
注意如果UI线程忙,timer事件将不会立即被触发(除非你使用了DoEvents)
timer的Enable属性默认是false,需要改成true才能开始工作
Timer 事件在activity 活动暂停或一个阻止对话框可见时不会被触发,Timers 需要在Process_Globals中声明
否则你可能会在activity 重新创建时产生多个timers过程
如果activity 暂停,建议将timer也暂停,在activity恢复时重新开启,这样能节省CPU和电量损耗
事件:
Tick
成员:
Enabled As Boolean
Initialize (EventName As String, Interval As Long)
Interval As Long
成员描述:
Enabled As Boolean
Initialize (EventName As String, Interval As Long)
初始化定时器,并指定事件名和触发间隔时间(毫秒).
注意:这个对象一定要在Process_Globals中声明
例如:
Timer1.Initialize("Timer1", 1000)
Timer1.Enabled = True
Sub Timer1_Tick
'Handle tick events
End Sub
Interval As Long
获取或设置定时器的触发间隔(毫秒)