Public Class frmGreetings

  Private Sub btnArray_Click(ByVal sender As System.Object,
                             ByVal e As System.EventArgs) Handles btnArray.Click
    Dim ub As Integer = lstBox.Items.Count - 1   'upper bound of array
    Dim a(ub) As String
    For i As Integer = 0 To ub
      a(i) = CStr(lstBox.Items(i))
    Next
    IO.File.WriteAllLines("Greetings1.txt", a)
  End Sub

  Private Sub btnSW_Click(ByVal sender As System.Object,
                          ByVal e As System.EventArgs) Handles btnSW.Click
    Dim sw As IO.StreamWriter = IO.File.CreateText("Greetings2.txt")
    For i As Integer = 0 To lstBox.Items.Count - 1
      sw.WriteLine(lstBox.Items(i))
    Next
    sw.Close()
  End Sub

End Class
