(Link to AcmlmWiki) Offline: thank ||bass
Register | Login
Views: 13,040,846
Main | Memberlist | Active users | Calendar | Chat | Online users
Ranks | FAQ | ACS | Stats | Color Chart | Search | Photo album
04-23-23 03:03 AM
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
Posted on 02-03-06 09:15 PM Link | Quote
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
Posted on 02-03-06 09:19 PM Link | Quote
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
Posted on 02-03-06 09:58 PM Link | Quote
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
Posted on 02-04-06 12:08 AM Link | Quote
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"
Dim LongVar As Long: LongVar = FreeFile
Dim PutString As String: PutString = StringVar & vbCrLf

If Dir("Data") <> "" Then Kill "Data"
Open "Data" For Binary Access Write As LongVar
Put LongVar, 1, PutString
Close LongVar

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
Posted on 02-04-06 03:18 AM Link | Quote
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
Posted on 02-04-06 11:14 AM Link | Quote
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
Dim FileLines() As String, NumLines As Long
Dim FileNum As Long, FileData As String

'Set the filename
Filename = "Data"

'Check for file existance
If Dir(Filename) = "" Then
MsgBox "File access error:" & vbCrLf & _
"File not found", vbCritical
Exit Sub 'College professors will discourage this
End If

FileNum = FreeFile 'Find a usable file number
Open Filename For Binary Access Read As FileNum
FileData = Space(LOF(FileNum)) 'Allocate space
Get FileNum, 1, FileData 'Read all file data
Close FileNum

'Parse the file data at a newline (vbCrLf)
FileLines = Split(FileData, vbCrLf)
NumLines = UBound(FileLines) + 1 'Get number of lines



(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
Posted on 02-04-06 01:10 PM Link | Quote
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) |


ABII

Acmlmboard 1.92.999, 9/17/2006
©2000-2006 Acmlm, Emuz, Blades, Xkeeper

Page rendered in 0.016 seconds; used 383.20 kB (max 464.81 kB)