SolvedSave Listbox To Text

Posts 1–6 of 6 · Page 1 of 1
Save Listbox To Text
Hey guys had alook around on the net on how to save the text in a listbox to a txt file. But I can't seem to get it to work the txt file just comes up blank, heres the code im using maybe someone knows a better way. Thanks

Code:
Dim SaveFile As New SaveFileDialog
        SaveFile.FileName = "Protection Log"
        SaveFile.Filter = "Text Files (*.txt)|*.txt"
        SaveFile.Title = "Save"
        SaveFile.ShowDialog()
        Try
            Dim Write As New System****.StreamWriter(SaveFile.FileName)
            Write.Write(ListBox3.Items)
            Write.Close()
        Catch ex As Exception
        End Try
Code:
Using sfd As New SaveFileDialog() With { .Filter = "Text Files (*.txt)|*.txt", .FileName = "Protection Log", .Title = "Save" }
    If sfd.ShowDialog().Equals(DialogResult.OK)
        Try
            IO.File.WriteAllLines(sfd.FileName, ListBox1.Items.Cast(Of Object)().Select(Function(i) i.ToString()).ToArray())
        Catch ex As Exception
        End Try
    End If
End Using
Thanks buddy works perfectly +rep, Im also interested in creating a time elapsed feature. Is there an easy way to do it.

Thanks
Quote Originally Posted by silentrunner2 View Post
Thanks buddy works perfectly +rep, Im also interested in creating a time elapsed feature. Is there an easy way to do it.

Thanks
You can use the stopwatch class to consume elapsed feature:

Code:
Dim SW As New StopWatch()
SW.Start()
'Do some synchronous tasks here...
SW.Stop()
MsgBox("These tasks were completed in: " & SW.Elapsed.ToString())
Quote Originally Posted by Hassan View Post


You can use the stopwatch class to consume elapsed feature:

Code:
Dim SW As New StopWatch()
SW.Start()
'Do some synchronous tasks here...
SW.Stop()
MsgBox("These tasks were completed in: " & SW.Elapsed.ToString())
I don't understand how to use that? I just want it to show in a label and count up kinda like this 00:00:01, I know how to do that but not in real time like 60seconds per minute.
Quote Originally Posted by silentrunner2 View Post
I don't understand how to use that? I just want it to show in a label and count up kinda like this 00:00:01, I know how to do that but not in real time like 60seconds per minute.
Create a Timer (From Toolbox). Set following properties:

Enabled = True
Interval = 1000

Double click Timer (which will take you to the Tick event handler of Timer). Paste the following code in it:

Code:
If Not SW.IsRunning Then
SW.Reset()
SW.Start()
End If
Label1.Text = SW.Elapsed.ToString
Replace Label1 with the name of your Label control.
Posts 1–6 of 6 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us