使用Lotusscript逐行读取配置文本

使用Lotusscript逐行读取配置文本

  在编写代码的过程中,我们很希望自己的程序足够灵活,有能力对后来功能变更。这时比较好的办法是使用配置文件,配置文件最常见的是Apache httpd的文件(如图1),可以看到每一行就一个配置项目,行首如果是以#开始则为注释,代码在读取时会自动忽略。
使用Lotusscript逐行读取配置文本_第1张图片

图1

  接下来我们在Domino通过Lotusscript也实现类似的按行读取配置的代码:

代码部署

  创建一个文本文件(名称可以随便定义,我这里命名为syncJcsjdb.cfg),文件路径为服务器数据路径的\domino\html\下
  syncJcsjdb.cfg的内容示例如下:
使用Lotusscript逐行读取配置文本_第2张图片

图2

程序部署

	Dim session As New NotesSession
	Dim dbCur As NotesDatabase
	Dim vwCur As NotesView				'临时变量,表示源数据视图
	Dim docSource As NotesDocument
	
	Dim strDirectoryPath As String		'服务器的Data目录
	Dim strCfgFile As String			'服务器上html目录下的配置文件
	Dim strText As String, fileNum As Integer
	
	Set dbCur = session.Currentdatabase
	strDirectoryPath = session.Getenvironmentstring("Directory", true)
	
	If strDirectoryPath = "" Then
		MsgBox "从notes.ini中读取服务器Directory配置失败,请检查notes.ini配置。"
		Exit sub
	End If
	strCfgFile = strDirectoryPath + "\domino\html\syncJcsjdb.cfg"
	
	Dim strDiff As String			'误差配置字段值
	fileNum% = FreeFile()
	Open strCfgFile For Input As fileNum%
	Do While Not EOF(fileNum%)
		Line Input #fileNum, strText$
		If InStr(strText$, "Difference=") = 1 Then
			strDiff = Replace(strText$,"Difference=","")
		End If
	Loop

  注:以上代码中,

Line Input #fileNum, strText$

  即为按行读取文本的代码;

If InStr(strText$, “Difference=”) = 1 Then

  表示若存在这个配置项,则执行if段中的代码;

strDiff = Replace(strText$,“Difference=”,"")

  表示读取等号后面的配置值

你可能感兴趣的:(Domino开发)