如何打list框的值保存?(在线等待)100分

pegdw 2003-07-15 10:47:16
具体情况:
我要把list1列表框的值选到list2列表框,并把list2列表框值保存起来,
下次打开工程时list2列表框值还是上次的值。(注:不用数据库方式)。
...全文
34 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
lihonggen0 2003-07-15
  • 打赏
  • 举报
回复

建立与读取.ini文件

 

  虽然进入win95之後,一般读写ini文件被读写Registry所取代,但我们还是可以透过
win31的传统方式读写ini文件,以存程式目前的相关设定,而於下一次程式执行时再
读回来。目前建议使用GetSetting SaveSetting的方式存於Registry中,不用目前
的方式。 储存程式的设定
'请於form中放3个TextBox,一个CommandBox
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

Private Sub Command1_Click()
Dim success As Long
success = WritePrivateProfileString("MyApp", "text1", Text1.Text, "c:\aa.ini")
'叁数一 Section Name
'叁数二 於.ini中的项目
'叁数三 项目的内容
'叁数四 .ini文件的名称
success = WritePrivateProfileString("MyApp", "text2", Text2.Text, "c:\aa.ini")
success = WritePrivateProfileString("MyApp2", "text3", Text3.Text, "c:\aa.ini")
End Sub

Private Sub Form_load()
Dim ret As Long
Dim buff As String
buff = String(255, 0)
ret = GetPrivateProfileString("Myapp", "text1", "text1", buff, 256, "c:\aa.ini")
'若.ini MyApp中无text1,则采用叁数三的值
Text1.Text = buff
buff = String(255, 0)
ret = GetPrivateProfileString("Myapp", "text2", "text2", buff, 256, "c:\aa.ini")
Text2.Text = buff
buff = String(255, 0)
ret = GetPrivateProfileString("Myapp2", "text3", "text3", buff, 256, "c:\aa.ini")
Text3.Text = buff
End Sub



 


pegdw 2003-07-15
  • 打赏
  • 举报
回复
可以具体一点吗?
lihonggen0 2003-07-15
  • 打赏
  • 举报
回复
建议保存在ini文件
pegdw 2003-07-15
  • 打赏
  • 举报
回复
这是俺头的做法:
写入:
Select Case cbo收付.Text
Case "应收"
Close
Open App.path & "\应收.ini" For Output As #1
For i = 0 To List2.ListCount - 1
Write #1, List2.ItemData(i)
Next i
Close #1

Case "应付"
Close
Open App.path & "\应付.ini" For Output As #1
For i = 0 To List2.ListCount - 1
Write #1, List2.ItemData(i)
Next i
Close #1
End Select
读取:
Private Sub cbo收付_Click()
Dim X As Long
Close
List2.Clear
Select Case cbo收付.Text

Case "应收"
Open App.path & "\应收.ini" For Input As #1
Do While Not EOF(1)

Input #1, X
For i = 0 To List1.ListCount - 1
If List1.ItemData(i) = X Then
List2.AddItem List1.List(i)
List2.ItemData(List2.NewIndex) = X
Exit For
End If
Next i

Loop
Close #1
Case "应付"
Open App.path & "\应付.ini" For Input As #1
Do While Not EOF(1)

Input #1, X
For i = 0 To List1.ListCount - 1
If List1.ItemData(i) = X Then
List2.AddItem List1.List(i)
List2.ItemData(List2.NewIndex) = X
Exit For
End If
Next i

Loop
Close #1
End Select

End Sub


7,784

社区成员

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

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