I want to save an array of UShort integers in any chosen directory,
using a Common Dialog Box. (There seem to be big differences between
VB6 and VB Express.) Can anyone help And I need to load back the
values, again using a Dialog Box.
Thanks,
David.

Common Dialog Box and Save- newbie question
boone10
David.
markusp
Hi David,
May I suggest http://msdn2.microsoft.com as another place to search for APIs that you're not sure about.
If you want to save something as Binary, you can use the BinaryWriter class. See http://msdn2.microsoft.com/en-us/library/system.io.binarywriter.write(VS.80).aspx.
Best regards,
Sachit Kachraj
nice to hear its working
plz mark the answer for your question as answer
SmokeNMirrors
Hi,
Notice this line of code in the sample
Dim FileName As String = SaveFileDialog.FileName
To get the file path from the dialog box into the code that writes and reads the file you can:
WriteToFile(FileName)
To quickly read / write text to the file, you can use My.Computer.FileSystem.ReadAllText and My.Computer.FileSystem.WriteAllText.
Best regards,
A_M
Hi David,
You can add a new MDIParent form into your project and take a look at the OpenFileDialog and SaveFileDialog sample in there. Here's a copy of the code:
Dim OpenFileDialog As New OpenFileDialog
OpenFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
OpenFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
If (OpenFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
Dim FileName As String = OpenFileDialog.FileName
' TODO: Add code here to open the file.
End If
Dim SaveFileDialog As New SaveFileDialog
SaveFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
SaveFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
If (SaveFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
Dim FileName As String = SaveFileDialog.FileName
' TODO: Add code here to save the current contents of the form to a file.
End If
Best regards,
felix21685
here is the sample code for saving message "TESTING" with a file name "testing.txt" in directory C:\
ok
'Open StreamWriter to Write
Dim sw As New IO.StreamWriter("C:\")
' acually write the message into the file
sw.Writeline("TESTING")
'properly close the stream
sw.close
Well, I just learned this a day or two ago so I might not have the comments right, but this works (at least to save unformatted text messages)
Hope this helps
-Keehun Nam
Scott Munro
Any ideas
David.
Henry Zhang
hi,
yes , you can use streams, you can use richtextbox.save(...) that depend on your case
hope this helps
bajaexplorer
After many hours of searching and Googling and reading, and incorporating the help from your reply, I've cobbled together the code below. (The File Read code is similar, using StreamReader.) It seems to do the job although there are some commands I don't understand. Maybe you can see some flaws or offer suggestions for improvements.
Also, is there a method of saving my UShort array as binary, rather than converting it to String data and then reconverting when it loads
Dim Save As New SaveFileDialog()
Dim sw As System.IO.StreamWriter
Save.Filter = "Plain Text Files (*.txt)|*.txt|All files (*.*)|*.*"
Save.CheckPathExists = True 'Not sure what this does.
Save.Title = "Save Data"
If (Save.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
Try
sw = System.IO.File.CreateText(Save.FileName)
For i = 1 To 9
For j = 1 To 9
sw.WriteLine(CType(U(i, j), String))
sw.WriteLine(CType(SFlag(i, j), String))
Next
Next
sw.Flush() ' I don't know what this does.
sw.Close()
Catch ex As Exception ' I don't know what this does.
MsgBox("ERROR: " & ex.Source & " : " & ex.Message, MsgBoxStyle.OkOnly)
End Try
End If
Thanks,
David.