10/31/2011 07:37 by KevinHan
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.
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.
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.
Close the StreamWriter object and the sub statement with the following:
writer.Close()
End Sub
A: Click "Start" and"Run." Enter "Setup.1st." Click "Start" and "Notepad." Open the "Notepad" application. Open the "Setup.1st" fil...(more)
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)
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)
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)
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)
Added Successfully!
×Voted Successfully!
×You can't vote for yourself
×You can't choose your own answer
×