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 WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long 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 LongPrivate Sub Form_Load() Open "C:\aa.ini" For Output As #1 Print #1, "文件内容" Close #1 End SubPrivate Sub Label1_Click() On Error GoTo Errhandle ShellExecute Me.hwnd, "open", "www.sohu.com", vbNullString, vbNullString, 1 Exit Sub Errhandle: MsgBox Err.Description & "!", vbInformation End Sub'写INI文件 Private Sub Command1_Click() Dim Counter As Long For Counter = 1 To 4 Call WriteToIni(App.Path & "\Options.ini", "Test", "Name" & Counter, "Value" & Counter) Next Counter End Sub'读INI文件 Private Sub Command2_Click() Dim Counter As Long Dim Value(3) As String For Counter = 1 To 4 Value(Counter - 1) = ReadFromIni(App.Path & "\Options.ini", "Test", "Name" & Counter) Next Counter End Sub
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
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 LongPrivate Sub Form_Load()
Open "C:\aa.ini" For Output As #1
Print #1, "文件内容"
Close #1
End SubPrivate Sub Label1_Click()
On Error GoTo Errhandle
ShellExecute Me.hwnd, "open", "www.sohu.com", vbNullString, vbNullString, 1
Exit Sub
Errhandle:
MsgBox Err.Description & "!", vbInformation
End Sub'写INI文件
Private Sub Command1_Click()
Dim Counter As Long For Counter = 1 To 4
Call WriteToIni(App.Path & "\Options.ini", "Test", "Name" & Counter, "Value" & Counter)
Next Counter
End Sub'读INI文件
Private Sub Command2_Click()
Dim Counter As Long
Dim Value(3) As String For Counter = 1 To 4
Value(Counter - 1) = ReadFromIni(App.Path & "\Options.ini", "Test", "Name" & Counter)
Next Counter
End Sub
请教射天狼,您的程序中: ReadFromIni,WriteToIni函数定义在哪儿
或下一个INI类用
INI文件一般是配置文件吧,节点名称应该是固定已经知道的,怎么还要获取呢?
[section1]
[section2]
.
.
.
[sectionN] (N=1,2.......K)
N具体是多少未知