添加三个按钮,一个List1,一个text1。然后运行,点击保存后关闭程序在开启你会发现刚刚保存的数据依然存在
给你看看我自己做了个类似程序的软件方便使用代码
Dim a As Boolean, i As Long
Private Sub Command1_Click()
If Text1.Text = "" Then
MsgBox "单词不能为空白"
Exit Sub
End If
For i = 0 To List1.ListCount - 1
If List1.List(i) = Text1.Text Then a = True
Next i
If a = False Then
List1.AddItem Text1.Text
Else
MsgBox "单词重复"
a = False
End If
End Sub
Private Sub Command2_Click()
If List1.ListIndex <> -1 Then
If MsgBox("是否删除当前单词", vbYesNo) = vbYes Then List1.RemoveItem List1.ListIndex
End If
End Sub
Private Sub Command3_Click()
Dim sj As String
For i = 0 To List1.ListCount - 1
sj = sj & "####" & List1.List(0) & "@@@@"
List1.RemoveItem 0
Next i
Open "C:\newwords.txt" For Output As #1
Print #1, sj
Close #1
Dim ss As String
Open "C:\newwords.txt" For Binary As #1
ss = Input(LOF(1), #1)
Close #1
Do While InStr(1, ss, "#") <> 0
List1.AddItem Split(Split(ss, "####")(1), "@@@@")(0)
ss = Replace(ss, "####" & Split(Split(ss, "####")(1), "@@@@")(0) & "@@@@", "")
Loop
End Sub
Private Sub Form_Load()
Dim ss As String
Open "C:\newwords.txt" For Binary As #1
ss = Input(LOF(1), #1)
Close #1
Do While InStr(1, ss, "#") <> 0
List1.AddItem Split(Split(ss, "####")(1), "@@@@")(0)
ss = Replace(ss, "####" & Split(Split(ss, "####")(1), "@@@@")(0) & "@@@@", "")
Loop
End Sub