小弟对以下代码一直很不理解,请各位大哥帮忙解读一下?
Public Type ConnStrParam
server As String
database As String
uid As String
pwd As String
End Type
Public Function convertStr(ByVal line As String, t As String) As String
Dim i As Long
Dim n As Long
Dim a As Long
Dim temp As String
n = Len(line)
convertStr = ""
If t = "w" Then
For i = 1 To n
temp = Mid(line, i, 1)
a = Asc(temp)
a = a + 5
temp = Chr(a)
convertStr = convertStr & temp
Next
Else
For i = 1 To n
temp = Mid(line, i, 1)
a = Asc(temp)
a = a - 5
temp = Chr(a)
convertStr = convertStr & temp
Next
End If
End Function
Public Sub writeConnStrFile(ByRef p As ConnStrParam)
On Error GoTo lberr
Dim fpath As String
fpath = App.Path & "\conf.dat"
Dim fs, f
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.CreateTextFile(fpath, True)
f.WriteLine (convertStr(p.server, "w"))
f.WriteLine (convertStr(p.database, "w"))
f.WriteLine (convertStr(p.uid, "w"))
f.WriteLine (convertStr(p.pwd, "w"))
f.Close
Set fs = Nothing
Exit Sub
lberr:
MsgBox Err.Description, vbCritical, CStr(Err.Number)
End Sub
Public Sub getConnStr(ByRef p As ConnStrParam)
On Error GoTo lberr
Dim fpath As String
fpath = App.Path & "\conf.dat"
If FileExist(fpath) Then
Dim fs, f
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile(fpath, 1, 0)
'-------server----------------------
p.server = convertStr(f.ReadLine(), "r")
'---------database------------------
p.database = convertStr(f.ReadLine(), "r")
'---------uid--------------------------
p.uid = convertStr(f.ReadLine(), "r")
'---------pwd--------------------------
p.pwd = convertStr(f.ReadLine(), "r")
f.Close
Set fs = Nothing
End If
Exit Sub
lberr:
MsgBox Err.Description, vbCritical, CStr(Err.Number)
End Sub
请问怎样通过conf.dat文件读取数据库的路径???