Brothersoft.comWindows|Mac|Mobile|Games

|Message

Solve software problem quickly Share experience to help others Improve the ability of solving problem
How to Write an Array to a File in Visual Basic?

10/31/2011 07:37 by KevinHan

First answer posted by JPhillippy at 10/31/2011 07:37
Add Your Answer
10~1000 characters in length CAPTCHA:
2 Answers
  • JPhillippy
    1. Create or open the sub statement you want to use to write your array to a file. For example:

      Private Sub WriteArray()

      This creates a new sub statement that you may call anytime in your program.

    2. Declare your StreamWriter object with the following line:

      Dim writer As System.IO.StreamWriter = New System.IO.StreamWriter("path_to_file", True)

      Replace the quoted string with the actual path to the file you will use to save the array. For example, "C:\myFile.txt" uses a text file in the C:\ folder. The second parameter is a Boolean value used to determine what you want to happen if the file already exists. "True" means you want to append to an existing file while "False" means you want to overwrite it. If no file exists, VB will automatically create it.

    3. Use a loop to write the contents of your array to the file:

      For i = 0 To sizeOfArray

      writer.Write(myArray(i))

      writer.WriteLine()

      Next i

      The "Write" sub writes a character to the file. In the case of your array, it will write the entire contents of each array index, specified by the counter "i." The "WriteLine" sub simply writes a new line to the file to keep each array value separate.

    4. Close the StreamWriter object and the sub statement with the following:

      writer.Close()

      End Sub

  • Was this answer helpful? 00 · 10/31/2011 07:37
  • Anonymous user
  • THANKS BUDDY

  • Was this answer helpful? 00 · 12/21/2011 12:03
  • Add Your Answer
    10~1000 characters in length CAPTCHA:
    Related Questions
    Q:How to Remove System Files With Visual Basic?

    A: Click "Start" and"Run." Enter "Setup.1st." Click "Start" and "Notepad." Open the "Notepad" application. Open the "Setup.1st" fil...(more)

    Q:How to Limit a Text Box to Numbers Only in Visual Basic 6.0?

    A: Load the Visual Basic 6.0 environment by clicking the program's shortcut icon from the desktop, or selecting "Microsoft Visual Basic 6.0" fr...(more)

    Q:How to Read Text Files with Visual Basic?

    A: Define a variable for your text file. When the Visual Basic compiler reads in the file, it needs a variable to save the information. To defi...(more)

    Q:How to Create a Text File in Visual Basic 6?

    A: Click the Windows Start menu button and type "Visual Basic." When the Visual Basic icon appears in the search results window, click that ico...(more)

    Q:How to Write Data Files in Visual Basic?

    A:Writing Text Data Create a new Visual Basic project by clicking on "File" and "Create New Pproject." Continue to click "Next" or "OK" to any...(more)

    0 people are following

    Ask a question now
    Write a title for your question

    WampServer

    WampServer is a Windows web development environment.
    Latest version:2.1e
    License:Freeware
    OS:Windows Vista/XP/2000/98/Me/NT
    Total downloads:119,868
    Rank:5 in Databases
    Download It

    Share with friends

    New features is coming

    • 1. Providing high-quality answers to be a verified Q&A expert
    • 2. Ask and answer questions to get Brothersoft credits

    Added Successfully!

    ×

    Are you sure to delete your answer?

    NoYes

    ×

    Are you sure to choose it as the best answer?

    NoYes

    ×

    Voted Successfully!

    ×

    You can't vote for yourself

    ×

    You can't choose your own answer

    ×