![]() |
| Register | Login | |||||
|
Main
| Memberlist
| Active users
| Calendar
| Chat
| Online users Ranks | FAQ | ACS | Stats | Color Chart | Search | Photo album |
|
| | |||
| 0 users currently in Programming. |
| Acmlm's Board - I3 Archive - Programming - VB6 - Writing a string variable (variable equivalent of varname.WriteLine) |
New poll | | ![]() |
| Add to favorites | Next newer thread | Next older thread |
| User | Post | ||
|
Sukasa Birdo Not quite as active as before. Xkeeper supporter Xk > ||bass I IP Banned myself! Twice! Since: 11-17-05 From: Somewhere over there Last post: 5908 days Last view: 5907 days |
| ||
| Yeah, I'm using the new FileSystemObject in my code for some software for my school, and I'm having problems. I've managed to get everything to work except one thing: I can't write the data I edit after I finish with the program. The code goes in the Form_Unload() subroutine, and the ONE line I'm having problems with is this one:
Ts.WriteLine Strings(a) Now, Ts is a TextStream object, and Strings(a) is a string variable in for loop a. I need to know what command I can use instead to write the string variable to the file, followed by a newline character. |
|||
|
HyperHacker Star Mario Finally being paid to code in VB! If only I still enjoyed that. <_< Wii #7182 6487 4198 1828 Since: 11-18-05 From: Canada, w00t! My computer's specs, if anyone gives a damn. STOP TRUNCATING THIS >8^( Last post: 5907 days Last view: 5907 days |
| ||
| What is it supposed to write to? Debug.Print might do it. | |||
|
Sukasa Birdo Not quite as active as before. Xkeeper supporter Xk > ||bass I IP Banned myself! Twice! Since: 11-17-05 From: Somewhere over there Last post: 5908 days Last view: 5907 days |
| ||
| The program writes the variable to a file in the same folder as the program, named "Data", with no extension.
It's actually a .txt file to the program, but in the interests of looking official and not something to be messed with by oother students, I used "Data" instead of "Pages.txt". |
|||
|
Guy Perfect Since: 11-18-05 Last post: 5909 days Last view: 5907 days |
| ||
Erm... I just use the intrinsic file I/O methods... Get and Put with the file opened as Binary...
Dim StringVar As String: StringVar = "FreeBASIC or Bust" |
|||
|
Sukasa Birdo Not quite as active as before. Xkeeper supporter Xk > ||bass I IP Banned myself! Twice! Since: 11-17-05 From: Somewhere over there Last post: 5908 days Last view: 5907 days |
| ||
| OK, So I can use that code to write the lines to the File, and then use the FileSystemObject to read from them, or do I need to change anything for that?
Thank you very much, BGNG. |
|||
|
Guy Perfect Since: 11-18-05 Last post: 5909 days Last view: 5907 days |
| ||
| I highly recommend not using the FileSystemObject in the first place. These days, there's more of a push towards productivity than efficiency, which is why everything tends to lean towards object-oriented programming. The truth of the matter is, using lower-level functions and statements is much faster and much more effective on the performance of the program. They're really not particularly inconvenient, either.
You can allocate the necessary memory in a String variable to hold all the contents of a text file, then parse it into a string array by splitting it at each newline. Using a dynamic string array and the Split() function, you can parse any string into an array of strings using a fixed delimiter, such as the newline constant vbCrLf. Split() will set the lower bound of an undimensioned array to 0, which will end up being the first line of the file in the end. So in the code below, FileLines(0) is the first line of the file. The only thing you'll really have to worry about is the size of the file. But since text files don't usually get bigger than, say, 10MB (process logs defy the rule), you should be just fine. Observe: Dim Filename As String (edited by BGNG on 02-04-06 02:15 PM) |
|||
|
Sukasa Birdo Not quite as active as before. Xkeeper supporter Xk > ||bass I IP Banned myself! Twice! Since: 11-17-05 From: Somewhere over there Last post: 5908 days Last view: 5907 days |
| ||
| All right, so I can use that to load the data into my array, and have each entry in the array be one of the lines?
Cool, that really helps. I'd probably change the MsgBox and Exit Sub lines to something that rebuilds the Data file, and then I can place that into my load routine, as well as change the freefile to nothing, and hardcode data as #1, since that's the only file the program ever opens. Also, I shouldn't need NumLines, sinc the array is excatly 25 lines large, and enything bigger would mean that the data file has been tampered with. |
| Add to favorites | Next newer thread | Next older thread |
| Acmlm's Board - I3 Archive - Programming - VB6 - Writing a string variable (variable equivalent of varname.WriteLine) |
| ![]() |