HTML

html content help to improve the coding

Saturday, 31 March 2012

STRING ARRAY INTO TEXT FILE IN VB.NET

An array is a data structure that contains multiple variables of the same type. Arrays helps us create shorter and simpler code in many situations. Arrays in VB.NET inherit from the Array class in the System namespace.
  Dim months(11) As String
An array allows you to refer to these related values by the same name and to use a number, called an index or subscript, to tell them apart. The default number of array elements is set to zero and the reference element is set to null.
The elements of an array can be of any type, including an array type. The following VB.NET source code shows how to write the array content into a text file.

Public Class Form1

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

  Dim months(11) As String
  months(0) = "Jan"
  months(1) = "Feb"
  months(2) = "Mar"
  months(3) = "Apr"
  months(4) = "May"
  months(5) = "Jun"
  months(6) = "Jul"
  months(7) = "Aug"
  months(8) = "Sep"
  months(9) = "Oct"
  months(10) = "Nov"
  months(11) = "Dec"
  System.IO.File.WriteAllLines("c:\file.txt", months)

 End Sub
End Class

No comments:

Post a Comment