Read a text file

Anything Really. Just keep it clean!

Moderators: Dorian (MJT support), JRL

Post Reply
rba88usa
Newbie
Posts: 5
Joined: Mon Apr 03, 2017 7:33 pm

Read a text file

Post by rba88usa » Mon Apr 03, 2017 7:46 pm

I have develop a code with While loop. but I need to read a file line by line, and I have tried the sample but it did not work. Can anyone correct the script because the ReadLn gives me an error. I need to read a text file and put the field into a web form, and then do something come back and read the line 2 and so forth. Here is the code. Thanks for the help.

19284 19284 119284192849284//Set IGNORESPACES to 1 to force script interpreter to ignore spaces.
//If using IGNORESPACES quote strings in {" ... "}
//Let>IGNORESPACES=1
Dim line as global
ReadFile>C:\Users\nvbautr\Documents\test1.txt,strFileContents

Let>k=1
While>line<>##EOF##
//ReadLn>C:\Users\nvbautr\Documents\test1.txt,k,line
if>line<>##EOF##

MouseMove>352,465
LClick
Wait>2
SendText>line
SetFocus>Schedule Class Meetings - Internet Explorer
CapsOff
Press Enter
Wait>2
MouseMove>518,110
LClick
Press Tab
MouseMove>45,434
LClick
Endif
let>k=K+1
EndWhile

User avatar
Marcus Tettmar
Site Admin
Posts: 7394
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Read a text file

Post by Marcus Tettmar » Tue Apr 04, 2017 9:03 am

You need to increment the line counter:

Let>k=k+1

But I would read a text file like this:

Code: Select all

ReadFile>filename,text
Separate>text,CRLF,lines
If>lines_count>0
Let>k=0
Repeat>k
  Let>k=k+1
  Let>line=lines_%k%
Until>k=lines_count
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

rba88usa
Newbie
Posts: 5
Joined: Mon Apr 03, 2017 7:33 pm

Re: Read a text file

Post by rba88usa » Thu Apr 06, 2017 3:03 pm

Thanks for the answer, and I have tried, but it does not read the file line. If I provide the specifics maybe you will be able to help me further.
I have a form on a web page, where I have to put some information in order to search. The information is on a text file, here is the sample of the text

123456
234567
987456
234590

So, the script have to be able to read the text file and grab the field 12345, go to the active web page and plug it into the correct box and click search(that part is working fine), but when I run this macro I can't read 12345, it just give me line(the name of the field),then the next step once I click search is to do something, then go back to the original web page and grab the second line of the text file 234567 and do the process again, and then the third until the end. Here is the code I am using, thanks for helping.

19284 19284 119284192849284//Set IGNORESPACES to 1 to force script interpreter to ignore spaces.
//If using IGNORESPACES quote strings in {" ... "}
//Let>IGNORESPACES=1
Dim line as global
ReadFile>C:\Users\nvbautr\Documents\test1.txt,text
Separate>text,CRLF,lines
if>lines_count>0
Let>k=0
Repeat>k
let>k=k+1
Let>line=lines_%k%
MouseMove>352,465
LClick
Wait>2
SendText>line
SetFocus>Schedule Class Meetings - Internet Explorer
CapsOff
Press Enter
Wait>2
MouseMove>518,110
LClick
Press Tab
MouseMove>45,434
LClick
Until>k=lines_count



Endif

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Re: Read a text file

Post by CyberCitizen » Thu May 04, 2017 1:01 pm

Sorry for the late reply, hopefully this helps get you started.

IfFileExists>%DESKTOP_DIR%\Test.txt
Let>vCount=1
While>vLineNum<>##EOF##
ReadLn>%DESKTOP_DIR%\Test.txt,vCount,vLineNum
If>vLineNum<>##EOF##
MessageModal>vLineNum
Endif
Let>vCount=vCount+1
EndWhile
Else
MDL>File Not Found, Press Ok To Create The File & Run The Script To Try Again
Let>WLN_NOCRLF=1
WriteLn>%DESKTOP_DIR%\Test.txt,,123456%CRLF%234567%CRLF%987456%CRLF%234590
Exit>0
EndIf

  View Snippet Page
FIREFIGHTER

rba88usa
Newbie
Posts: 5
Joined: Mon Apr 03, 2017 7:33 pm

Re: Read a text file

Post by rba88usa » Tue Feb 06, 2018 9:25 pm

Thanks for the help, it worked really well.
Can you help me to read a file that contains fields separated by comas, so I can read a line get the first field, transfer to a web form, then go back and read the next field, and so forth. thanks.

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts