How Do I use Arrays and Read/Write to a file? RRS feed

  • Question

  • Hello

    Could anyone help me with a couples of queries with using arrays and reading / writing from a file?

    With Arrays do I create and use them in the same way as in Visual Basic 6?

    Would anyone write a basic code for me to look at please?

    With Reading and writing to a file, I'm unable to write multiple lines of text and numbers to a file.

    Write#FileNumber,TextBox1,TextBox2 then replace Write with Read to read back the data from a file, is this different in Visual Express as I was unable to get it to work in the past.  Again, would anyone write a sample code for me to look at?


    Thank, You.

    Saturday, October 22, 2011 4:40 PM


  • Have a look at the following - it illustrates a number of techniques.  You could look up in Help anything you've not met before.

       Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
          Dim Filename As String = "d:\temp\testfile1.txt"
          Dim IntArray() As Integer = {1, 2, 3, 4, 5, 6}
          Using SW As New IO.StreamWriter(Filename)
             For Each Item As Integer In IntArray
          End Using
          Dim AnotherArray(5) As Integer
          Dim Count As Integer
          Using SR As New IO.StreamReader(Filename)
             Do While Not SR.EndOfStream
                AnotherArray(Count) = CInt(SR.ReadLine)
                Count += 1
          End Using
          For Counter As Integer = 0 To 5
       End Sub


    Saturday, October 22, 2011 5:01 PM