如何访问 *.ini 里的数据,请各位指点一二!

caoliyong 2003-05-30 04:17:39
我自己用VB做了一个小程序,用来发送命令的。*.ini里存储有命令类型和命令。每种命令类型都有若干条命令,怎样访问才能做到我发送的命令是我选中命令类型中的命令。
存储方式为:
命令类型一
命令一
命令二
命令类型二
命令一
命令二
命令类型三
命令一
命令二
请各位指点一二
...全文
49 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
caoliyong 2003-07-09
  • 打赏
  • 举报
回复
我搞不太清楚这两个函数,能不能举个例子将详细一点
friendwei 2003-07-09
  • 打赏
  • 举报
回复
你用什么开发的呀。我这是 vb 的
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (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
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long

Public Function read_ini(sINIfile As String, sSection As String, sKey As String, sDefault As String) As String
On Error GoTo err_msg
Dim sTemp As String * 256
Dim nLength As Integer

sTemp = Space$(256)
nLength = GetPrivateProfileString(sSection, sKey, sDefault, sTemp, _
256, sINIfile)
read_ini = Left$(sTemp, nLength)
Exit Function
err_msg:
MsgBox "Read system ini.file is wrong!", vbInformation + vbOKOnly, "system error!"
End Function

Public Sub write_ini(sINIfile As String, sSection As String, sKey As String, sValue As String)
On Error GoTo err_msg
Dim n As Integer
Dim sTemp As String
sTemp = sValue
For n = 1 To Len(sValue)
If Mid$(sValue, n, 1) = vbCr Or Mid$(sValue, n, 1) = vbLf Then _
Mid$(sValue, n) = ""
Next n
n = WritePrivateProfileString(sSection, sKey, sTemp, sINIfile)
Exit Sub
err_msg:
MsgBox "write system ini.file is wrong!", vbInformation + vbOKOnly, "system error!"
End Sub
will521 2003-07-08
  • 打赏
  • 举报
回复
取值
ProFileString('c:\aa.ini','peld-1',up,'')
写值
SetProFileString('c:\aa.ini','peld-1',up,字符串)
gflpower 2003-07-08
  • 打赏
  • 举报
回复
看一下这两个函数
profilestring()
setprofilestring()
caoliyong 2003-07-08
  • 打赏
  • 举报
回复
假如我知道了一个UP的值,用什么方法才能确定这个UP是[peld-1]下面的,还是[peld-2]下面的
payzq 2003-06-27
  • 打赏
  • 举报
回复
up
zjp899 2003-06-26
  • 打赏
  • 举报
回复
在vc里面是这么用的
char File[256];
char Temp[256];

wsprintf(File, ".\\*.ini");
if (_access(File, 00) == -1)
{
AfxMessageBox("请确认在当前目录下有 '*.ini' 文件");
return;
}

GetPrivateProfileString("peld-1", "up", "0", Temp, 20, ".\\*.ini");
//结果在Temp中

在vb中,没有用过,不知是否如此!
caoliyong 2003-06-24
  • 打赏
  • 举报
回复
具体是这样的*.ini
[peld-1]
up=字符串
down=字符串
[deld-2]
up=字符串
down=字符串
请讲具体一点
yjw1018 2003-06-21
  • 打赏
  • 举报
回复
先搬凳子占个位。
pling 2003-06-11
  • 打赏
  • 举报
回复
应该在程序中说明吧,比如作一个命令选单,
ok?

2,209

社区成员

发帖
与我相关
我的任务
社区描述
其他数据库开发 其他数据库
社区管理员
  • 其他数据库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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