读书人

关于读取文件有关问题

发布时间: 2012-01-20 18:53:53 作者: rapoo

关于读取文件问题
各位大虾帮偶看一下,偶写了一段代码,能保存我的输入的内容.但好像读取不出来??
在线等哦,,,


'读取数据库

Public Sub readServer()
On Error GoTo aaaa
Dim strtmp As String, strT() As String
Open " File\sql.inf " For Input As #1
If EOF(1) = False Then
Line Input #1, strtmp
End If
Close #1
strtmp = Trim(strtmp)
If strtmp <> " " Then
strT = Split(strtmp, "|| ")
For i = 0 To 3
strT(i) = strT(i)
Next
strSQLServer = strT(0)
strSQLUser = strT(1)
strSQLPwd = strT(2)
strSQLDb = strT(3)
End If
Exit Sub
aaaa:
strSQLServer = " "
strSQLUser = " "
strSQLPwd = " "
strSQLDb = " "
Exit Sub
End Sub


'保存sql服务器配置信息

Public Sub saveserver(ByVal strServer As String, ByVal strUser As String, ByVal strDb As String)

Open "File\sql.inf " For Output As 1#
Print #1, strServer; "|| "; strUser; "|| "; strPwd; "|| "; strDb
Close #1
Exit Sub
aaaa:
MsgBox "保存SQL服务器信息失败! ", vbCritical

End Sub

[解决办法]
读取文件的格式不对~~~当打开文件时不能光有文件名,还要有路径
例如:Open "c:\File\sql.inf " For Output As 1#

读书人网 >VB

热点推荐