vb 怎么把listbox的内容保存入ini
vb怎么把listbox的内容保存入ini,再次启动窗口时再读取ini放入listbox!说明:读取和保存的数据都是变化的,怎么循环读去和循环保存?...
vb 怎么把listbox的内容保存入ini,再次启动窗口时再读取ini放入listbox!
说明:读取和保存的数据都是变化的,怎么循环读去和循环保存? 展开
说明:读取和保存的数据都是变化的,怎么循环读去和循环保存? 展开
3个回答
展开全部
Dim strIniFileName As String
' 定义API函数
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
' 为方便使用,把两个API函数封装起来
Function ReadIniFile(ByVal filename As String, ByVal AppName As String, ByVal KeyName As String) As String
Dim temp As String * 100
Dim n As Long
n = GetPrivateProfileString(AppName, KeyName, "", temp, Len(temp), filename)
ReadIniFile = Mid(temp, 1, n)
End Function
Function WriteIniFile(ByVal filename As String, ByVal AppName As String, ByVal KeyName As String, ByVal NewKeyName As String)
Dim n As Long
n = WritePrivateProfileString(AppName, KeyName, NewKeyName, filename)
End Function
Private Sub Command1_Click() '保存ListBox到INI
Dim i As Integer
strIniFileName = App.Path & "\mirsoft.ini"
Call WriteIniFile(strIniFileName, "总行数", "行", List1.ListCount)
For i = 0 To List1.ListCount - 1
Call WriteIniFile(strIniFileName, "自定义文本", "文本" & i, List1.List(i))
Next
End Sub
Private Sub Form_Load()
Dim i As Integer, j As Integer
'读取INI,恢复ListBox
strIniFileName = App.Path & "\mirsoft.ini"
j = Val(ReadIniFile(strIniFileName, "总行数", "行"))
For i = 0 To j - 1
List1.List(i) = ReadIniFile(strIniFileName, "自定义文本", "文本" & i)
Next
End Sub
展开全部
保存:
Private Sub command1_click()
Dim i As Integer
Open "D:\save.ini" For Output As #1
For i = 0 To List1.ListCount - 1
Print #1, List1.List(i)
Next
Close #1
End Sub
保存:
Private Sub command2_click()
Dim tem As String
List1.Clear
Open "D:\save.ini" For Input As #2
Do While Not EOF(2)
Line Input #2, tem
List1.AddItem tem
Loop
Close #2
End Sub
Private Sub command1_click()
Dim i As Integer
Open "D:\save.ini" For Output As #1
For i = 0 To List1.ListCount - 1
Print #1, List1.List(i)
Next
Close #1
End Sub
保存:
Private Sub command2_click()
Dim tem As String
List1.Clear
Open "D:\save.ini" For Input As #2
Do While Not EOF(2)
Line Input #2, tem
List1.AddItem tem
Loop
Close #2
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-07-29
展开全部
修正LS
代码的笔误:
Private Sub Command2_Click() '保存
Dim i As Integer
Open "D:\save.ini" For Output As #1
For i = 0 To List1.ListCount - 1
Print #1, List1.List(i)
Next
Close #1
End Sub
Private Sub Command3_Click() '读取
Dim tem As String
List1.Clear
Open "D:\save.ini" For Input As #2
Do While Not EOF(2)
Line Input #2, tem
List1.AddItem tem
Loop
Close #2
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询