非常简单的问题,可是我不会,请帮忙....

suxi 2003-06-14 03:44:39
conn.ini配置文件中有如下配置参数:
Database = "mydb"
login = "mylog"
password = "mypwd"

在vb中用何命令从上面文件中读出各节点参数?我对vb 不是很熟悉,请高手帮忙...
...全文
29 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
ydzqw 2003-06-14
  • 打赏
  • 举报
回复
引用了kernel32函数?
就几个API啊,挺简单的
: bydisplay(时光) 的方法不是很好哦,还有BUG

suxi 2003-06-14
  • 打赏
  • 举报
回复
请教中海,我引用了kernel32函数,可程序总出错,指示内存为只读?是何原因?
GetWindowPos 2003-06-14
  • 打赏
  • 举报
回复
Function Getini() As String
Dim PassWord As String
PassWord = Space(20)
rstr = GetPrivateProfileString("", "database", "", PassWord, 20, "conn.ini")
Getini = Left(PassWord, rstr)
End Function
极速小王子 2003-06-14
  • 打赏
  • 举报
回复
INI文件格式:
[TITLE]
KEY1=...
KEY2=...
...
----------------------------------------------------------
conn.ini配置文件中有如下配置参数:
Database = "mydb"
login = "mylog"
password = "mypwd"
你可以使用API函数:
GetPrivateProfileString (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
第一个参数:相当于TITLE
第二个参数:相当于KEY
第三个参数:默认返回字符串
第四个参数:返回的字符串
第五个参数:字符串长度
第六个参数:文件路径
qingming81 2003-06-14
  • 打赏
  • 举报
回复
下面三项前面还有一个标题,叫什么?
Database = "mydb"
login = "mylog"
password = "mypwd"
pigsanddogs 2003-06-14
  • 打赏
  • 举报
回复
哈哈bydisplay(时光),你怎么也有这个, 跟我们公司以前写的一样的哦!
不过后来换API了, 更好, 就是中海提供的那个
victorycyz 2003-06-14
  • 打赏
  • 举报
回复
看来我的速度不够快:(
victorycyz 2003-06-14
  • 打赏
  • 举报
回复
参考此贴
http://expert.csdn.net/Expert/topic/1895/1895312.xml?temp=.3579218
bydisplay 2003-06-14
  • 打赏
  • 举报
回复
Function setProfile(strFileName As String, strSection As String, strName As String, strSave As String) As Boolean
'这个函数是用来对INI文件进行写操作的
'函数说明:
'strFileName 是所要存储的文件名
'strSection 是这个文件中的一个节点名
'strName 是所要查找的字段名
'strSave 是所要替换字段值

Dim strTemp As String
Dim strfileback As String
Dim strreturn As String
strfileback = App.Path & "\xj.tmp" '临时文件是用来存放中转信息的

Open strFileName For Input As #1
Open strfileback For Output As #2
Do While Not EOF(1)
Line Input #1, strTemp
strreturn = strTemp
Print #2, strreturn
If InStr(1, Trim(strTemp), "[") <> 0 Then
If InStr(1, Trim(strTemp), Trim(strSection)) <> 0 Then
Do While Not EOF(1)
Line Input #1, strTemp
If InStr(1, Trim(strTemp), Trim(strName)) <> 0 Then Exit Do '找到所要修改的字段值
strreturn = strTemp
Print #2, strreturn '拷贝不需要的字段值
Loop
strreturn = strName & "=" & strSave '修改
Print #2, strreturn
End If
End If
Loop
Close #1
Close #2
Open strfileback For Input As #1
Open strFileName For Output As #2
Do While Not EOF(1) And EOF(2)
Line Input #1, strreturn
Print #2, strreturn
Loop
Close #1
Close #2
End Function
Function GetProfile(strFileName As String, strSection As String, strName As String) As String
'这个函数是用来对INI文件进行读操作的
'函数说明:
'strFileName 是所要读取的文件名
'strSection 是这个文件中的一个节点名
'strName 是所要查找的字段名
'返回值:
strSectionTemp = ""
strNameTemp = ""
strreturn = ""
On Error GoTo ErrSrchSection
Open strFileName For Input As #1
' 下面这段程序是用来查找节点的
Do While Not EOF(1)
strCharA = Input(1, #1)
If strCharA = "[" Then
Do While Not EOF(1)
strCharB = Input(1, #1)
If strCharB = "]" Then Exit Do
strSectionTemp = strSectionTemp & strCharB
Loop
End If
If strSectionTemp = strSection Then
strCharA = Input(2, #1)
Exit Do
Else
strSectionTemp = ""
End If
Loop
On Error GoTo ErrReadFile

aa:
'下面这段程序是用来查找所要查找的字段的
strNameTemp = ""
Do While Not EOF(1)
strCharA = Input(1, #1)
If strCharA <> "=" Then
strNameTemp = strNameTemp & strCharA '得到名称
Else
Exit Do
End If
Loop
If strNameTemp = strName Then
Line Input #1, strreturn '如果找到与它匹配的字段名,就返回得到的值
Else
Line Input #1, strreturn '如果未找到与它匹配的字段名,就继续找
GoTo aa
End If
Close #1
GetProfile = strreturn
Exit Function
ErrReadFile:
Dim inrRet As Integer
intret = MsgBox("在文件中没有找到所要查找的字段", vbAbortRetryIgnore, "错误信息")
Select Case intret
Case vbAbort
GetProfile = ""
Close #1
Exit Function
Case vbRetry
Resume
Case vbIgnore
Resume Next
End Select
ErrSrchSection:
MsgBox "节点未找到", vbOKOnly
GetProfile = ""
Close #1
End Function











txtLogPass = GetProfile(strPath, "mydb", "mylog")
sxs69 2003-06-14
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/topic/1895/1895312.xml?temp=.5577509

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧