|
-
Apr 3rd, 2010, 07:50 AM
#1
Thread Starter
Addicted Member
Save Dialog
hi vbforums
how do i save everything thats in a listbox and save dialog shows exatensions like .txt .text .html .htm .url types and it writes to where you save it too also check path files would be awesome
thanks
-
Apr 3rd, 2010, 08:02 AM
#2
Re: Save Dialog
There's a couple of separate, basically independent questions in there. Saving data from a listBox to a file is the same whether you use a SaveFileDialog or not. Using a SaveFileDialog is the same no matter what you're saving. This is an example of where you should break the problem down into its components. Understand the components independently and then you can use them anywhere, independent of each other.
So, to the SaveFileDialog first. Create an instance, set its properties appropriately and then call ShowDialog. If that returns OK then the user clicked OK and you get the selected file from the FileName property. Simple. If you want to know what properties to set you should read the MSDN documentation to see what properties it has and what each one is for.
As for saving the contents of a ListBox, it depends on what the items are and how you want to save them. I'll assume that the items are Strings and you want to save each to a line in a text file. In that case, you'd create a StreamWriter and then use a For Each loop to enumerate the items, calling WriteLine for each one.
-
Apr 3rd, 2010, 09:56 AM
#3
Thread Starter
Addicted Member
Re: Save Dialog
yea its a list box full of numbers and letters here is the code i got to far but it doesnt save
Dim myFileDialog As SaveFileDialog = New SaveFileDialog()
With myFileDialog
.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
.FilterIndex = 1
.InitialDirectory = "C:\"
.Title = "Save File"
.CheckFileExists = False
End With
If myFileDialog.ShowDialog() = DialogResult.OK Then
RandomPassAndNumberListBox.Text.ToString()
Console.WriteLine(myFileDialog.FileName)
End If
myFileDialog = Nothing
End Sub
-
Apr 4th, 2010, 10:13 PM
#4
Re: Save Dialog
It doesn't save because you have no code to save. Did you read the last paragraph of my previous post?
-
Apr 5th, 2010, 09:48 AM
#5
Thread Starter
Addicted Member
Re: Save Dialog
i did but im still on my first application teaching me self but didnt understand what you wanted me 2 do
-
Apr 5th, 2010, 08:35 PM
#6
Re: Save Dialog
 Originally Posted by pillhead2007
i ... didnt understand what you wanted me 2 do
Step 1
 Originally Posted by jmcilhinney
you'd create a StreamWriter
Step 2
 Originally Posted by jmcilhinney
use a For Each loop to enumerate the items
Step 3
 Originally Posted by jmcilhinney
calling WriteLine for each one
You don't have to worry about step 2 and step 3 until you've completed step 1. So, create a StreamWriter. If you don't know how to create a StreamWriter then you should either read the documentation or look for examples.
http://www.google.com.au/search?q=cr...ient=firefox-a
As you can see, there is plenty of information available.
-
Apr 6th, 2010, 01:28 PM
#7
Addicted Member
Re: Save Dialog
This code:
Code:
Dim i As Integer
Dim wsw As IO.StreamWriter
SaveFileDialog2.Title = "Save Games List"
SaveFileDialog2.DefaultExt = ".txt"
SaveFileDialog2.FileName = "Have List"
SaveFileDialog2.ShowDialog()
wsw = New IO.StreamWriter(SaveFileDialog2.FileName)
For i = 0 To RandomPassAndNumberListBox.Items.Count - 1
wsw.WriteLine(RandomPassAndNumberListBox.Items.Item(i))
Next
wsw.Close()
Should do it, it prompts the user to choose a location and file name, then saves a .txt file containing a list of all the items in the listbox. Attach it to a click event etc (like on a button) and then test it out.
-
May 13th, 2010, 02:28 PM
#8
Thread Starter
Addicted Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|