I need to read one line of a txt and then store it to a string. Then take that string and use it to build a different file. Once that is finished it needs to go back and read line two.Any ideas?This is what I'm working with.Dim FSys as new FileSystemObjectDim strAddress as stringDim strSubject as stringDim strBody as stringprivate Sub Form_Load() Call ReadFilesEnd Subprivate Sub genEmail() Dim OutStream as TextStream outEmail = App.Path & "outEmail.txt" set OutStream = FSys.CreateTextFile(outEmail, true, false) OutStream.WriteLine "..h1 " & strAddress OutStream.WriteLine "..h2 " & strSubject OutStream.WriteLine "..h3 " & strBody OutStream.WriteLine "..h4 SEND" set OutStream = nothing EndEnd Subprivate Sub ReadFiles()Dim InStream as TextStream BodyText = App.Path & "ody.txt" set InStream = FSys.OpenTextFile(BodyText, 1, false, false) While InStream.AtEndOfStream = false TLine = InStream.ReadLine strSubject = strSubject & TLine & vbCrLf TLine = InStream.ReadAll strBody = strBody & TLine & vbCrLf Wend ' Text1.Text = strBody set InStream = nothing Call GetAddressEnd Subprivate Sub GetAddress() Dim AddressInStream as TextStream AddressText = App.Path & "email.txt" set AddressInStream = FSys.OpenTextFile(AddressText, 1, false, false) While AddressInStream.AtEndOfStream = false TLine = AddressInStream.ReadLine 'strAddress = strAddress & TLine & vbCrLf strAddress = TLine & vbCrLf Wend 'Text1.Text = strAddress & strBody 'Text1.Text = strAddress & strBody set AddressInStream = nothing Call genEmailEnd Sub
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
FSO ReadLine && EOF?
Hey everyone, need some insight into FSO ReadLine, please.
I want to use the FSO (File System Object) ReadLine to read a text file. As each line is read, I want to assign that
particular text line to a variable. How do I know when the contents of the text file is at the "End Of File (EOF)"?
And, what would be the best way to set up these variables?
Since I don't know how many lines might be in the text file, how can I properly prepare to create variables
"on the fly" as these lines are read (array?) ?
TIA for your time and help!
ReadLine And Tabs
I have a problem. When I tell the program to do something it it finds a line with tabs, it just doesn't find it.
Here's the line:
codeToFind = "@[""a_b""] // c"
it doesn't find this. But when I take out the tab and change the text file it's searching appropriately, it does find it. What's going on? Is there certain code needed to tell it that tabs are there other than just copying and pasting the code from the file into the program?
p.s. I'm using inputFile.ReadLine to read the file
p.p.s. How can I get a progress bar to show how much of the file has been read?
I read file using textstream object and its method ReadLine.But with some files it seems that it doesn't get newLine character.Instead it read many lines at once and a little square appears at the place of linefeed.
Does anybody have an idea where the problem comes from?
I'm using FSO to populate an array. This works fine in Access 2003, but 2000 and 2002 jumble all the readline into the first array. The textfile has 5+ lines.
Here's the code:
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile(strPath, ForReading)
strEmail(1) = f.readline
strEmail(2) = f.readline
strEmail(3) = f.readline
strEmail(4) = f.readline
strEmail(5) = f.ReadAll
Set fs = Nothing
Excuse me..appreciate for your big help here..
Question: My program below only able to detect the first keyword and then terminate the program. How can I let my program to continue to read the remaining line so that it will be able to detect the other keywords that exist in a file?
Look at my code here:
Dim Fsys As New FileSystemObject
Dim InStream As TextStream
TestFile = "a: ext1.txt"
Set InStream = Fsys.OpenTextFile(TestFile, 1, False, False)
While InStream.AtEndOfStream = False
RawdataStr = InStream.ReadLine
If InStr(RawdataStr, " keyword") <> 0 Then
'other code here'
Set InStream = Nothing
How Do I Get This >ReadLine To Work In The Code Below
I am new to vb. I am working on this and need help in getting it to work.
Below is how my code looks like. I am trying to read data from an excel spreadsheet on a floppy disk. I am trying to display it based on my search criteria on a reults form. I am frustrated after trying for a whole week and still cannot get it to work.
It keeps erroring at the .ReadLine, the error says -
[object does'nt support this property or method]
Could somebody look in the code to see what I am doing wrong.
I will appreciate help--thanks
MAIN FORM CODE
Public gblnCancel As Boolean
Private Sub cmdCancel_click()
gblnCancel = True
Private Sub cmdGetFile_Click()
'cmd will allow user to browse for a file using the common dialog control'
.CancelError = True
txtFileToPrint.Text = .FileName
Private Sub cmdOk_Click()
Private Sub Form_Load()
If frmPastDueAmt.gblnCancel = True Then
Private Sub Form_Unload(Cancel As Integer)
Dim iAnswer As Integer
iAnswer = MsgBox("Are you sure you want to cancel?", vbYesNo)
If iAnswer = vbNo Then
Cancel = True
RESULTS FORM CODE
Public Sub PrintFile(strFileName As String)
Dim fsoFileSystem As FileSystemObject 'the file system
Dim tsFileToPrint As TextStream 'the file we will open
Set fsoFileSystem = New FileSystemObject
Set tsFileToPrint = fsoFileSystem.OpenTextFile(strFileName)
While Not .AtEndOfStream 'loop until the end of file
Print .ReadLine 'read a line and print it
Wend 'loop until the end of file
Set tsFileToPrint = Nothing 'deallocate the text stream
Set fsoFileSystem = Nothing 'deallocate the reference to the file
Readline (fso) Versus Mcafee
I've written a VB6 program that contain FSO script (I've let a example at the end of this message) However each time I run th problem Mcafee advertize me that the running script i suspicious. It's possible to desactivate the "scriptstopper" o Mcafee, but is there a better way to write a function that coul read and write and text file without being seen by Macafee as "good" program?
Vb6 ReadLine() Type Command
Code: so im in a vb6 programming class
and we are writing a console emulator
[[ looks like a console with certian commands as well as commands we write ourselves ]]
ive made a writetoconsole command
Public Sub WriteToConsole(ByVal text As String)
frmMain.tbConsole.text = frmMain.tbConsole.text & vbCrLf & text
and an opentoconsole command
Code: Public Sub opentoconsole(path As String)
Dim sLine As String
Dim intFile As Integer
intFile = FreeFile
On Error GoTo Hell
Open path For Input As #intFile
While Not EOF(intFile)
Line Input #intFile, sLine
frmMain.tbConsole.text = frmMain.tbConsole.text & sLine & vbCrLf
how would I write a ReadLine() command that reads the next line entered and imediatly responds to it?
ReadLine Method On A String Instead Of A File?
I have created a file that I use as my program's config file and I use the Readline method to read in the startup variables.
Now I have encrypted the file, so my program now has to unencrypt it and THEN use the WriteLine method to make a new file and then the Readline method again to get the varibles since I do 1 varaible per line. These leaves me volnurable since now the program has to write the config settings to a file in between reading it an encrypting it back again. There MUST be a better way, how can I use the ReadLine method on a string once I have unencrypted it in memory instead of a file?
Readline, Arrays, Split Function, Etc
im not sure what im doing here... i am trying to take a line of string from an existing file (the first line contains four pieces of data separated by colons), read the line, split it at each colon, then assign each of the four pieces of data to a new string variable... im lost!
Dim MyArray(3) As String
Dim strData As String
Dim sr As StreamReader
sr = New StreamReader(dlgOpen.FileName)
Do While sr.Peek <> -1
MyArray = sr.ReadLine().Split(":"c)
MyArray(0) = mstrAcctName
MyArray(1) = mstrAcctBal
MyArray(2) = mstrChkNum
MyArray(3) = mstrDepNum
*RESOLVED* Trim Function Objfile.readline
I am using scripting/file system objects to read lines from text file...
one of my lines is a few characters long but has spaces afterwards...
I inserted a breakpoint in the code to see what objfile.readline was coming back with and its like the characters of the line and where the spaces are square boxes (denoting the space character)...
so when I go to perform the Trim function, it will not trim off the "spaces" because it thinks that there is a box there technically in the string (even though when you go to display it in a msgbox or something it doesn't show the box ... can i get it to trim off this "box" so it just has the characters?
Private Sub LoadArray(ByVal scanfile As String)Dim objfile As Scripting.TextStreamDim objfso As New Scripting.FileSystemObjectDim strline As StringSet objfile = objfso.OpenTextFile(scanfile, ForReading)Do Until objfile.AtEndOfStream strline = objfile.ReadLine strline = Trim(strline)'etc etc
Thanks for the ideas.
Garbage Characters Returned While Performing A Readline On An XML File.
I'm writing code to extract information from backup logs generated by Backup Exec 9.x. The backup logs are in the form of XML files. When I do a readline on the file I get garbage back where every other character is a little square.
Here is a snippet of an XML file from the backup exec logs
<?xml version="1.0" encoding="UTF-16"?>
</filler><server>Job server: BACKUPSERV
</server><name>Job name: FILESERV - FULL
</name><start_time>Job started: Sunday, August 29, 2004 at 6:00:05 AM
</start_time><type>Job type: Backup
</type><log_name>Job Log: BEX02369.xml
If I do a readline on the job server line (4th line in snippett above) I see the following assigned to the variable in the debugger
< / f i l l e r > < s e r v e r > J o b s e r v e r : B A C K U P S E R V
The data is there but it puts all those little squares in between each character.
Can anyone help me with this?
Command Line StdOut Truncating ReadLine After "&&"
Command Line StdOut Truncating ReadLine After "&"
I am having a problem where I have to execute a .BAT file and read the text stream it returns. The problem is that the lines it returns have a “&” in them and the ReadLine is truncating the text after the “&”. For example, when the line I expect to receive back is “Peter & Mary”, all I get back is “Peter”. Is there a way to have the entire line returned by the ReadLine? Hopefully, preserving most of my original code.
I have included the basic Visual Basic and .BAT code below. You will also need to add the “Windows Script Host Object Models” reference and the .bat file was called “RetrieveNames.bat”. Any help would be greatly appreciated.
START BAT FILE CODE:
IF "%1"=="couples_names" (goto :couples_names) ELSE (goto :end)
echo STEVE & DEANA
echo VIRGINIA & THOMAS
echo PETER & JENNIFER
END BAT FILE CODE:
START VB CODE:
Private Sub UserForm_Initialize()
Dim objShell As IWshRuntimeLibrary.WshShell
Dim objExec As IWshRuntimeLibrary.WshExec
Dim theLine As String
Dim strCMD As String
Dim GetDosOutput As String
'instatiate Shell object
Set objShell = New IWshRuntimeLibrary.WshShell
'Define BAT File To Call
strCMD = "RetrieveNames.bat couples_names"
'Execute the dos command
Set objExec = objShell.Exec(strCMD)
Do While objExec.StdOut.AtEndOfStream = False
'Grab The Next Line
theLine = objExec.StdOut.ReadLine
'get any standard err. output
GetDosOutput = GetDosOutput & objExec.StdErr.ReadAll
Set objShell = Nothing
Set objExec = Nothing
END VB CODE: