Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DeleteFile VBA Attachmate Reflections

Status
Not open for further replies.

airwolf09

Technical User
Dec 7, 2012
24
US
I am trying to delete the first line of text file using Attachmate Reflections 2011 VBA script. But the code does not work. How can I use "DeleteLines 1, 1"? any help would be appreciated.


Const ForReading = 1, ForWriting = 2, ForAppending = 3
Dim fs, f

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile("C:\Batch_Manipulator_File.txt", ForWriting, TristateFalse)

f.Write "Hello world!"
f.DeleteLines 1, 1
f.Close

fs.CopyFile "C:\Temp.txt", True
 
DeleteLines is not a method of the FileSystemObject.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Then, how would you delete a line on this text file? Thank You for the help
 
I usually read from given text file line by line and write only what I need to another text file. And after that I have this 'another' text file to deal with. No Attachmate Reflections 2011 needed, just simple VBA code with native functionality.

Have fun.

---- Andy
 
I am trying to read the text file that has a batch of accounts. I am creating a button that as soon as you click on it, it will read the first line of the text file. Then, pass that to Reflections 2011. Then, delete the first line of the text file. Leaving the second account as the first one. Then, repete the process as I press the button. Therefore, i need to figure out how to delete the first line using VBA code.
 
Why don't you do this:
"it will read the first line of the text file. Then, pass that to Reflections 2011."
Then read the second line of the text file. Then, pass that to Reflections 2011.
Then read the third line of the text file. Then, pass that to Reflections 2011.
...
Then read the last line of the text file. Then, pass that to Reflections 2011.
Delete file (if needed)

Why do you need to delete each line of the text file after you processed it?

Have fun.

---- Andy
 
I did that. The problem is that I have to stop at different screens. I am not truly trying to batch process. I am trying to have a button that would pass the account to Reflections from the TEXT file with all accounts. Once the user is done with the first account, then user can hit the same button and pass the second account. And so on. The only way I could think of was to read the text file, pass the account to reflections, delete the first line. Then the user would be ready for the second accound.
 
Well, you can stop any time:

Code:
Dim strTextLine As String

Open "C:\TEMP\Test.txt" For Input As #1
Do While Not EOF(1)              [green]' Loop until end of file.[/green]
    Line Input #1, strTextLine   [green]' Read line into variable.[/green]
    If vbNo = MsgBox("Do you want to continue and process Account " & strTextLine, _
        vbYesNo Or vbQuestion Or vbDefaultButton2, "Continue?") Then
            Exit Do
    End If[green]
    'Do your magic here[/green]
Loop
Close #1

Have fun.

---- Andy
 
If you absolutely want to use FSO, here's the code:

Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(sFile) Then
Set objFile = objFSO.OpenTextFile(sFile, 1)
Do Until objFile.AtEndOfStream
strTextLine = objFile.ReadLine
Call SomeSubToDoReflectionsStuff(strTextLine)
Loop
End If

But I agree with Andrzejek, learning how to do it natively is a great job skill to pick up, so it's worth your time to learn it:

 
I thank You for that code. But the main reason why I want to delete the line from the text file is to learn how to do this process.
 
What I would do is:
1. Read file A
2. Skip the line(s) I don't want any more
3. Write the rest to file B
4. Delete file A
5. Rename file B to be file A

Have fun.

---- Andy
 
Or, how about this:

I started with [tt]C:\TEMP\Test.txt[/tt] file that contained:
[tt]
ABC123 Line 1
XYZ666 Line 2
098UYT Line 3
Line 4
[/tt]
I want to Delete first 2 lines
Run this code:

Code:
Dim aryTemp() As String
Dim strInputData As String
Dim x As Integer
Dim iSkip As Integer
Dim strFile As String

strFile = "C:\TEMP\Test.txt"

iSkip = 2  [green]'Delete first 2 lines[/green]

Open strFile For Input As #1
strInputData = Input$(LOF(1), 1)
Close #1

aryTemp = Split(strInputData, vbCrLf)

Open strFile For Output As #1
For x = LBound(aryTemp) + iSkip To UBound(aryTemp)
    Print #1, aryTemp(x)
Next x
Close #1

Now my Text file contains just:
[tt]
098UYT Line 3
Line 4
[/tt]

Have fun.

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top