vb 怎麼对ini文件 中Section 值修改?
文件结构如下,要修改[bbbb]为[cccc][aaaa]a1=1a2=2[bbbb]b1=1b2=2...
文件结构如下,要修改[bbbb]为[cccc]
[aaaa]
a1=1
a2=2
[bbbb]
b1=1
b2=2 展开
[aaaa]
a1=1
a2=2
[bbbb]
b1=1
b2=2 展开
2个回答
展开全部
方法:建立一工程,随便命名
控件 8个command,2个text ,
代码如下:
'API声明
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Function GetPrivateProfileString Lib "Kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, lpKeyName As Any, ByVal lpDefault As String, ByVal lpRetunedString 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 lplFileName As String) As Long
‘变量声明
Private r As Long
Private entry As String
Private iniPath As String
’定义
Function GetFromINI(AppName As String, KeyName As String, FileName As String) As String
Dim RetStr As String
RetStr = String(255, Chr(0))
GetFromINI = Left(RetStr, GetPrivateProfileString(AppName, ByVal KeyName, "", RetStr, Len(RetStr), FileName))
End Function
Private Sub Command1_Click()
Text1.Text = GetFromINI("zc", "ID", iniPath)
End Sub
Private Sub Command8_Click()
End
End Sub
Private Sub Command2_Click()
Text2.Text = GetFromINI("yh", "NAME", iniPath)
End Sub
Private Sub Command4_Click()
entry$ = Text1.Text
r = WritePrivateProfileString("zc", "ID", entry, iniPath)
If r <> 1 Then MsgBox "error!"
End Sub
Private Sub Command5_Click()
entry = Text2.Text
r = WritePrivateProfileString("yh", "NAME", entry, iniPath)
If r <> 1 Then MsgBox "error!"
End Sub
Private Sub Command7_Click()
Text1.Text = GetFromINI("zc", "ID", iniPath)
Text2.Text = GetFromINI("yh", "NAME", iniPath)
End Sub
Private Sub Command3_Click()
Command4_Click
Command5_Click
End Sub
Private Sub Command6_Click()
Text1.Text = ""
Text2.Text = ""
End Sub
Private Sub Form_Load()
iniPath$ = App.Path + "\GLKJ.ini"
Command7_Click
End Sub
控件 8个command,2个text ,
代码如下:
'API声明
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Function GetPrivateProfileString Lib "Kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, lpKeyName As Any, ByVal lpDefault As String, ByVal lpRetunedString 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 lplFileName As String) As Long
‘变量声明
Private r As Long
Private entry As String
Private iniPath As String
’定义
Function GetFromINI(AppName As String, KeyName As String, FileName As String) As String
Dim RetStr As String
RetStr = String(255, Chr(0))
GetFromINI = Left(RetStr, GetPrivateProfileString(AppName, ByVal KeyName, "", RetStr, Len(RetStr), FileName))
End Function
Private Sub Command1_Click()
Text1.Text = GetFromINI("zc", "ID", iniPath)
End Sub
Private Sub Command8_Click()
End
End Sub
Private Sub Command2_Click()
Text2.Text = GetFromINI("yh", "NAME", iniPath)
End Sub
Private Sub Command4_Click()
entry$ = Text1.Text
r = WritePrivateProfileString("zc", "ID", entry, iniPath)
If r <> 1 Then MsgBox "error!"
End Sub
Private Sub Command5_Click()
entry = Text2.Text
r = WritePrivateProfileString("yh", "NAME", entry, iniPath)
If r <> 1 Then MsgBox "error!"
End Sub
Private Sub Command7_Click()
Text1.Text = GetFromINI("zc", "ID", iniPath)
Text2.Text = GetFromINI("yh", "NAME", iniPath)
End Sub
Private Sub Command3_Click()
Command4_Click
Command5_Click
End Sub
Private Sub Command6_Click()
Text1.Text = ""
Text2.Text = ""
End Sub
Private Sub Form_Load()
iniPath$ = App.Path + "\GLKJ.ini"
Command7_Click
End Sub
2013-09-15
展开全部
百度一下读写INI,到处都是
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询