Read/Update INI configration file function[VBS]

时间:2015-09-19 ┊ 阅读:2,343 次 ┊ 标签: 开发 , 编程 , 经验

'读取ini配置文件里的信息
'参数为ini文件路径,读取的key值
代码如下:

Function GetLastRunSave(strPath,strKeyName)
    Dim FSO, LastRunSave, strReadLine, StrKeyValue
    GetLastRunSave=""
    Set FSO = CreateObject("Scripting.FileSystemObject")
    If Not FSO.FileExists(strPath) Then
        FSO.CreateTextFile(strPath)
        Set LastRunSave = FSO.OpenTextFile(strPath, 2)
        LastRunSave.WriteLine "CheckOpt=NULL"
        LastRunSave.WriteLine "CheckApp=0"
        LastRunSave.Close
    End If
    Set LastRunSave = FSO.OpenTextFile(strPath, 1)
    Do Until LastRunSave.AtEndOfStream
        strReadLine = LastRunSave.ReadLine
        If instr(strReadLine,"=") <> 0 Then
            StrKeyValue = Split(strReadLine,"=")
            If trim(StrKeyValue(0)) = strKeyName Then
                GetLastRunSave = Trim(StrKeyValue(1))
                Exit Do
            End If
        End If
    Loop
    LastRunSave.Close
    Set FSO=Nothing
End Function

'把配置信息写到ini文件里,供程序跑时读取使用
'参数为,ini配置文件路径、key名字、key值
Sub SetLastRunSave(strPath,strKeyName,StrKeyValue)
    Dim FSO, LastRunSave, strReadLine, StrTmpKeyValue, strTmp
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set LastRunSave = FSO.OpenTextFile(strPath, 1)
    Do Until LastRunSave.AtEndOfStream
        strReadLine = LastRunSave.ReadLine
        If InStr(strReadLine,strKeyName) <> 0 Then
            StrTmpKeyValue = Split(Trim(strReadLine),"=")
            If Trim(StrTmpKeyValue(0)) = strKeyName Then
                strReadLine = strKeyName&"="&StrKeyValue
            End If
        End If
        strTmp = strTmp&strReadLine&vbcrlf
    Loop
    LastRunSave.Close
    Set LastRunSave = FSO.OpenTextFile(strPath, 2)
    LastRunSave.Write Trim(strTmp)
    LastRunSave.Close
    Set FSO=Nothing
End Sub

从百度空间搬回来的文章。

文章评论

添加新评论

温馨提醒:如果您是第一次在本站留言,需要审核后才能显示哦!

相关文章

Whatsapp只能查看最近三天的聊天记录了怎么办?

Whatsapp只能查看最近三天的聊天记录了怎么办?

今天突然发现电脑上的WhatsApp只能查看最近3天的聊天记录了,显示要查看3天前的记录请到手机上查看。很是吃惊,以前一直是所有记录都自动同步到电脑版的啊,不论换电脑了还是换手机了,聊天记录从来没丢过。 查询一翻也没有找出来原因,怎么也同步不过去。 电脑版app重新安装了,也不行。 有个方法说...
阅读全文>>
ValueError: Error getting directory

ValueError: Error getting directory

ssl证书过期了 明明自动renew的 然后看log已经好久没更新成功了 查半天是当前server不信任远程连接 只能自己改代码 报错: 21-12-17 13:01:11 Generate CSR...amkevin.csr amkevin.csr generated. /home/www...
阅读全文>>
网页路径中的'.'和'..'还有'./'和'../'区别

网页路径中的'.'和'..'还有'./'和'../'区别

. 表示当前目录 .. 表示当前目录的上一级目录。 ./表示当前目录下的某个文件或文件夹,视后面跟着的名字而定 ../表示当前目录上一级目录的文件或文件夹,视后面跟着的名字而定。 例如: 文件夹 a 下面有 文件夹b c 和文件 d。 文件夹b下面有e.php 和文件f。 则e中的 . 表示...
阅读全文>>
Introduction to ILE RPG Activation Groups

Introduction to ILE RPG Activation Groups

Learn how activation groups can help your ILE RPG programs run more efficiently, how to specify the type of group to use, and closing and reclaimin...
阅读全文>>
popup.js怎么和content.js通信?[JQuery]

popup.js怎么和content.js通信?[JQuery]

这两天为了实现一个谷歌浏览器插件功能,研究了半天怎么让插件来改特定网页里的特定字段的值,而这个值又来自popup的网页预先设定,下一步实现动态加载,可以让更多组实现便利。 目的很简单,我们有一个list,需要填到网页的某个字段,当然是好几个,这些值是设定好的,网页系统我们没法改,input想...
阅读全文>>