Lotusscript中的文件操作
来源:互联网 发布:科研民工 知乎 编辑:程序博客网 时间:2024/04/30 23:46
1、Sequential files
一般是文本文件,存储字符、ASCII控制字符。
【打开】
Open fileName [For {Input | Output | Append} ] As fileNumber [Len = bufferSize] [Charset = MIMECharsetName]
【写入】
Var1 = "123"
Var2 = 123
Print #idFile, Var1, Var2
将Var1和Var2的内容写入序号为idFile的文件中。Var1和Var2间将以tab间隔。文件内容:123
123
Write #idFile, "Testing", 123
作用同上,但是写入后,字符串两边将加入引号。Var1和Var2间将以逗号间隔。文件内容:"123",123
Note True, False, and NULL are stored as strings “#True#”, “#False#”, and “#NULL#”.
【读取】
Line Input # 读取一行
Do Until EOF(idFile)
Line Input #idFile, iLine
Print iLine
Loop
Input # 读取使用Write #方法写入的数据
Input #idFile, Var1, Var2 '可将文件内容读入Var1和Var2变量中。
Input 读取整个文件内容。Input返回Variant,Input$返回字符串。
' LOF returns the length of the file in characters.
Dim fulFile As String
fulFile = Input$(LOF(idFile), idFile)
2、Random files
存储长度相同的记录。记录可以为 Integer or String, or to a user-defined type。
【打开】
Open fileName For Random As fileNumber [Len = recordLength]
where recordLength is the length of each record in the file. The default length is 128 bytes.
Dim recLen As Integer, idFile As Integer
Dim recHold As emploRec
idFile = 1 ' The file number to use for
' this file
recLen = Len(recHold) ' The record length for this file
Open "DATA.DAT" For Random As idFile Len = recLen
【写入】
Put 新增或替换文件内记录。使用已有记录序号时为替换,使用任何大于已有序号时为新增。
Dim recNum As Integer
recNum = 5
' Replace record 5 with the contents of recHold.
Put idFile, recNum, recHold
【读取】
Get 将指定文件中指定序号的记录读取如指定变量中。
' The record number to retrieve from the file
Dim recNum As Integer
recNum = 5
' The variable to read into
Dim recHold As emploRec
Get idFile, recNum, recHold
3、Binary files
二进制文件。
【打开】
Open fileName For Binary As fileNumber
【写入】
Put fileNumber, bytePosition, variableName
bytePosition 文件中开始写入的位置。文件中第一byte对应的是position 1。
【读取】
Get fileNumber, bytePosition, variableName 与Put对应
Dim tempRec As emploRec
For I = recNum To lastRec - 1
Get idFile, I + 1, tempRec
Put idFile, I, tempRec
Next I
Seek [#] fileNumber, position 设置文件位置(Binary file中的字节位置或者Random file中的记录位置)。
Type personRecord
empNumber As Integer
empName As String * 20
End Type
Dim rec1 As personRecord, rec2 As personRecord
Dim fileNum As Integer, recNum As Integer
Dim fileName As String
fileNum% = FreeFile()
fileName$ = "data.txt"
recNum% = 5
Open fileName$ For Random As fileNum% Len = Len(rec1)
rec1.empNumber% = 123
rec1.empName$ = "John Smith"
Print Seek(fileNum%)
' Prints 1 for current position
Put #fileNum%, recNum%, rec1 ' Write data at record 5
Print Seek(fileNum%)
' Prints 6
Seek fileNum%, 1
' Rewind to record 1
Print Seek(fileNum%)
' Prints 1
Rec2.empNumber% = 456
Rec2.empName$ = "Jane Doe"
Put #fileNum%, , rec2
' Write at current position
Print Seek(fileNum%)
' Prints 2
Close fileNum%
dataHold = Input (numBytes, fileNumber) 从文件中读取numBytes字节数据至dataHold变量。若使用Input$,则返回值为String。
【总结】
【打开】
fileNumber% = FreeFile
Open fileName$ [ For {Input | Output | Append | Binary | Random }]
[ Access {Read | Read Write | Write}]
[ {Shared | Lock Read | Lock Read Write | Lock Write }]]
As fileNumber%
[ Len = recLen%]
[Charset = MIMECharsetName]
【关闭】
Close [ [ # ] fileNumber [ , [ # ] fileNumber ] ... ]
文件使用后必须关闭,否则不能被再次打开。改变文件打开属性(只读|可写)必须重新打开文件。
- Lotusscript中的文件操作
- lotusscript操作word文件中的Class wordDate
- lotusscript操作word文件
- 使用LotusScript操作纵txt文件
- LotusScript 操作 OpenOffice calc
- lotusScript文件夹操作
- lotusscript-拷贝文件
- lotusscript-删除文件
- 86. LotusScript中的数组函数
- 使用LotusScript操作Lotus Notes RTF域
- 34. LotusScript中的错误处理程序
- 85. BASIC和LotusScript中的Variant
- C++中的文件操作
- C++中的文件操作
- C#中的文件操作
- C#中的文件操作
- java中的文件操作
- VB中的文件操作
- J2EE架构的6个最佳实践 (转载)
- Hibernate的缓存机制介绍
- [中国][剧情][红美丽/葛优2007最新片][DVD-RMVB/348MB][国语中字]
- 男人最吸引女人的40个瞬间
- 搞定坏男人的最有效6大招数
- Lotusscript中的文件操作
- tomcat远程调试方法以及使用步骤(IDE是Jbuilder)
- 从女人的24个"死穴"下手!
- 日历控件
- 成长中必须知道的20个故事
- 数据仓库逻辑、物理结构及OLAP分析
- “鬼”样人生
- 做官宝典:一个老官对小官的赠言,字字千金
- 女性必读 :从A到Z