save and open question: sequential access files

eric2122

Member
Joined
Dec 12, 2007
Messages
5
Programming Experience
1-3
Hey I'm taking my first VB class and were just about done. We just learned about sequential access files but it was just the basics. I asked my prof and he didn’t know. What I need is some kind of dialog box that you can call to save and open sequential access files. Anybody know if visual studio has those or if I can find them somewhere?
 
What I need is some kind of dialog box that you can call to save and open sequential access files.

You may use dialog boxes for this

To show open file dialog,
VB.NET:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim OpenFileDialog1 As New OpenFileDialog()

        If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            'put your Code to open file here. OpenFileDialog1.FileName will give you the file name.
        End If

    End Sub

To show save file dialog
VB.NET:
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim SaveFileDialog1 As New SaveFileDialog()
        If SaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            'put your Code to save file here.
        End If
    End Sub
 
how do you imput data from the file name. i tried this but its not working for me

Dim instance As FileDialog
Dim value As String

value = instance.FileName

instance.FileName = value

My.Computer.FileSystem.WriteAllText(value, "line", False)
 
Dim instance As FileDialog
There is no FileDialog class.
you have to create a new instance of SaveFileDialog as follows
VB.NET:
Dim instance As New SaveFileDialog()

Then you should show that dialogbox and when the end user clicks ok button then you can save the file

VB.NET:
        If instance .ShowDialog() = Windows.Forms.DialogResult.OK Then
            My.Computer.FileSystem.WriteAllText(instance.FileName, "File contents", True)
        End If
 
What I need is some kind of dialog box that you can call to save and open sequential access files. Anybody know if visual studio has those or if I can find them somewhere?
They are in the Toolbox in the "Dialogs" tab, called OpenFileDialog and SaveFileDialog.
 
I understand how to read from a sequential access file and assign the text to a variable or display it in a text box:
VB.NET:
Private Sub OpenToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem1.Click
    Dim OpenFileDialog1 As New OpenFileDialog()
    If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
        text1 = My.Computer.FileSystem.ReadAllText(OpenFileDialog1.FileName)
        TextBox1.Text = My.Computer.FileSystem.ReadAllText(OpenFileDialog1.FileName)
    End If
End Sub

But how do you read specific lines from a sequential access file and assign them to different variables or textboxes in a form?
 
Last edited:
read the file contents into an array first. then you can add elements of the array to different textboxes

VB.NET:
Dim fileStr() As String = IO.File.ReadAllLines(OpenFileDialog1.FileName)
 
Back
Top