Settings
Do you need something made? then ask in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
Hello,
It would be best to use a text file for this:
To Save:
It would be best to use a text file for this:
To Save:
Code: Select all
To Load: With ListBox1
Dim t As Integer
Dim s As String = ""
For t = 0 To .Items.Count - 1
s += .Items(t).ToString & vbNewLine
Next
Try
My.Computer.FileSystem.DeleteFile("C:\MyListbox.txt", FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently)
Catch ex As Exception
End Try
My.Computer.FileSystem.WriteAllText("C:\MyListbox.txt", s, False)
End With
Code: Select all
Using sr As New IO.StreamReader("C:\MyListbox.txt")
Dim item As String = sr.ReadLine
While item <> Nothing
ListBox1.Items.Add(item)
item = sr.ReadLine
End While
End Using
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
Hello,
You could put the save code into the "Form_Closing" event and the load code into the "Form_Load" event handlers.
You could put the save code into the "Form_Closing" event and the load code into the "Form_Load" event handlers.
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
Ahhh... CodenStuff has forgot too tell you that you will need to manualy create C:\MyListbox.txt
But may i recomend putting the MyListbox.txt in the storage folder.. ?
But may i recomend putting the MyListbox.txt in the storage folder.. ?
Hello,
You need to check if the file exists first like:
For the load code:
You need to check if the file exists first like:
For the load code:
Code: Select all
If you want to have the file in your application directory you need to change "C:\MyListbox.txt" in both the save and load code to this:If Not My.Computer.Filesystem.FileExists("C:\MyListbox.txt") Then
My.Computer.FileSystem.WriteAllText("C:\MyListbox.txt", "", False)
End If
Using sr As New IO.StreamReader("C:\MyListbox.txt")
Dim item As String = sr.ReadLine
While item <> Nothing
ListBox1.Items.Add(item)
item = sr.ReadLine
End While
End Using
Code: Select all
Application.StartupPath & "\MyListbox.txt"
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
Copyright Information
Copyright © Codenstuff.com 2020 - 2023