Mell, There are a few things to cover with this problem. First off, the file extension does not matter as far as your program is concerned. Any file that you create and write to using the FileSystem in vb.net will create an ANSI text file that can be read just like a normal text file from notepad. You as the programmer have the option to change the extension if you want, but the contents will not change. Extensions are only there as footnotes to programs as to how they should interpret the data, they don't actually change the data within the file. Knowing that, all you need to do is step through the contents of your listbox with a loop and print each line to a file. In order to do this, use the above mentioned FileSystem inherent in vb.net. There are some syntax trickeries here. - FileSystem.FileOpen(filenumber, path, openmode)
- This will open an existing file or create a new one if one does not exist.
- filenumber - An integer value that will be the designation of the file for read/write operations.
- path - The full path to the file, including the complete filename and extension.
- openmode - a constant representing the method to access the file (input, output, append, binary, etc...)
- After you have opened the file, use FileSystem.PrintLine(filenumber, value) command to write to the file.
- This will write whatever value is to the next line of the file.
- When you are done writing to the file, close it with FileSystem.FileClose(filenumber).
- You now have a file on the drive with the data that you wrote to it. You can open it in notepad to see what it looks like, and you may have to do some testing to get it just right.
To read from the file is very similar, open it with FileSystem.FileOpen, but set the mode to input and use FileSystem.LineInput(FileNumber) to get each line of information. Again, make sure you test this a lot so you can get it just right. Each time you use the LineInput function, it will input one line from the file, so you may have to check against the FileSystem.EOF(FileNumber) property to see if you've reached the end of the file. Also, LineInput is a function, so you will have to set it against a string variable: as in varString = FileSystem.LineInput(FileNumber). I think I've covered everything, if I haven't let me know. By the way, the FileSystem object can be a very complex animal. What I've shown you here is the very basics of how to use it, but I've found that manipulating the basics can sometimes give you better results than the really complex functions. You just have to write more code. Best of Luck, Jim
Jim@nationalelectric.com
|