Sign in to follow this  
Followers 0
davykiash

Newbie Reading Text File Question

18 posts in this topic

hi

ive got a text file having the following format:

Bob 45 Nairobi

David 80 Kisumu

Kate 34 Eldoret

Alice 90 Kiambu

How do i loop through this lines of text while taking each value of text eg 'Bob' '45' and 'Nairobi' and writing it to 3 controls on a form?

let the contol names be Edit1,Edit2 and Edit3

my exe will clear the edit boxes after send("!S") before the loop proceeds to the next line.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

1

Welcome to the forums

2

you try we help - thats the policy ( you dont post-an-order to pick-up later

3

try looking into arrays and "stringsplit

8)

EDIT

A

filereadtoarray

b

stringsplit

c

guictrlcreateedit

d

for/next loop

e

guictrlsetdata

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

2

you try we help - thats the policy ( you dont post-an-order to pick-up later

:) That so reminds me of McDonalds - "Welcome to the AutoIt Forums, May we take your Order?" :(


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

:) That so reminds me of McDonalds - "Welcome to the AutoIt Forums, May we take your Order?" :(

Good one Ron!

LMAO... :D

8


NEWHeader1.png

Share this post


Link to post
Share on other sites

ok i am using the StringSplit function

$data = StringSplit(FileReadLine ($file) ,",")

ControlSend("Enter", "", "TEdit3",$data[1] )

my problem is that i dont want to use "," as the delimiter i want to use 'space'

How do i go about it

Share this post


Link to post
Share on other sites

ok i am using the StringSplit function

$data = StringSplit(FileReadLine ($file) ,",")

ControlSend("Enter", "", "TEdit3",$data[1] )

my problem is that i dont want to use "," as the delimiter i want to use 'space'

How do i go about it

$data = StringSplit(FileReadLine ($file) ," ")

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

$data = StringSplit(FileReadLine ($file) ," ")

like that

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

ok i am using the StringSplit function

$data = StringSplit(FileReadLine ($file) ,",")

ControlSend("Enter", "", "TEdit3",$data[1] )

my problem is that i dont want to use "," as the delimiter i want to use 'space'

How do i go about it

Then all you need to do is take out the "," and use " "
$data = StringSplit(FileReadLine($file), " ")
ControlSend("Enter", "", "TEdit3", $data[1] )

Edit:

Blah.. Too slow... Old age or lack of sleep ... take your pick!

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Thanks i got it

Its my first time to use the forum.

gimme time to understand it

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

ok i am using the StringSplit function

$data = StringSplit(FileReadLine ($file) ,",")

ControlSend("Enter", "", "TEdit3",$data[1] )

my problem is that i dont want to use "," as the delimiter i want to use 'space'

How do i go about it

and per your PM

davykiash Same old Newbie question, Today, 02:22 AM

http://index.php?CODE=05&act=Msg&MSID=22923&VID=in http://index.php?CODE=04&act=Msg&MID=12585&MSID=22923

Newbie

Group: Members

Posts: 3

Member No.: 12585

Joined: Yesterday, 12:33 AM

you dont get it

i am not creating GUI with autoit.The exe is already up and running.

what am doing am using autoit to interface my text files with ths exe.

go my question is simple.how do i use space as my delimiter?

this is the answer you want

$data = StringSplit(FileReadLine ($file) ," ")
ControlSend("Enter", "", "TEdit3",$data[1] )

8)

EDIT

glad you got it... after all that

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

My code is working fine but i receive an error when

the loop reaches the end of file.

The error is "Array variable has incorrect number of subscripts or subscripts dimension range exceeded"

i can tell the compiler to overide this error coz am getting the job done but is it wise?

$file = FileOpen("D:\Davy\AutoScripts\enterdata.txt", 0)

Run("D:\Davy\AutoScripts\enterdata\prjenter")

WinWait("Enter")

While 1

$data = StringSplit(FileReadLine ($file) ," ")

ControlSend("Enter", "", "TEdit3",$data[1] )

ControlSend("Enter", "", "TEdit2",$data[2] )

ControlSend("Enter", "", "TEdit1",$data[3] )

If @error = -1 Then ExitLoop

Send("!S")

Send("{ENTER}")

Wend

FileClose($file)

Exit

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

$file = FileOpen("D:\Davy\AutoScripts\enterdata.txt", 0)
Run("D:\Davy\AutoScripts\enterdata\prjenter")
WinWait("Enter")
While 1
    $data = StringSplit(FileReadLine($file), " ")
    If @error = -1 Then ExitLoop
    ControlSend("Enter", "", "TEdit3", $data[1])
    ControlSend("Enter", "", "TEdit2", $data[2])
    ControlSend("Enter", "", "TEdit1", $data[3])
    Send("!S")
    Send("{ENTER}")
WEnd
FileClose($file)
Exit

the error check needs to be after the file read

you may need to seperate the three

fileread-

check error-

stringsplit-

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

My code is working fine but i receive an error when

the loop reaches the end of file.

The error is "Array variable has incorrect number of subscripts or subscripts dimension range exceeded"

i can tell the compiler to overide this error coz am getting the job done but is it wise?

$file = FileOpen("D:\Davy\AutoScripts\enterdata.txt", 0)

Run("D:\Davy\AutoScripts\enterdata\prjenter")

WinWait("Enter")

While 1

$data = StringSplit(FileReadLine ($file) ," ")

ControlSend("Enter", "", "TEdit3",$data[1] )

ControlSend("Enter", "", "TEdit2",$data[2] )

ControlSend("Enter", "", "TEdit1",$data[3] )

If @error = -1 Then ExitLoop

Send("!S")

Send("{ENTER}")

Wend

FileClose($file)

Exit

Your error checking is off:
$file = FileOpen("D:\Davy\AutoScripts\enterdata.txt", 0)
Run("D:\Davy\AutoScripts\enterdata\prjenter")
WinWait("Enter")
While 1
    $data = StringSplit(FileReadLine($file) ," ")
    If @error = -1 Then ExitLoop
    ControlSend("Enter", "", "TEdit3",$data[1] )
    ControlSend("Enter", "", "TEdit2",$data[2] )
    ControlSend("Enter", "", "TEdit1",$data[3] )
    Send("!S")
    Send("{ENTER}")
WEnd
FileClose($file)
Exit

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

the error still persists.

it is at this line of code.

ControlSend("Enter", "", "TEdit2", $data[2])

it has nothing to do with the location of the code

If @error = -1 Then ExitLoop

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

the error still persists.

it is at this line of code.

ControlSend("Enter", "", "TEdit2", $data[2])

it has nothing to do with the location of the code

If @error = -1 Then ExitLoop
wrong again... post the error

8)

EDIT

should this

Run("D:\Davy\AutoScripts\enterdata\prjenter")

be.. this

Run("D:\Davy\AutoScripts\enterdata\prjenter.exe")

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

the error still persists.

it is at this line of code.

ControlSend("Enter", "", "TEdit2", $data[2])

it has nothing to do with the location of the code

If @error = -1 Then ExitLoop
Yes, it had "something" to do with the @error = -1, and to imply that we both posted the same exact thing at the same exact time, that we are both wrong is rather moronic.

If your getting an error @ $data[2] then there wasn't a space or there wasn't a $data[2]!

$file = FileOpen("D:\Davy\AutoScripts\enterdata.txt", 0)
Run("D:\Davy\AutoScripts\enterdata\prjenter")
WinWait("Enter")
While 1
    $data = StringSplit(FileReadLine($file) ," ")
    If @error = -1 Then ExitLoop
    If UBound($data) > 0 Then ControlSend("Enter", "", "TEdit3",$data[1] )
    If UBound($data) > 1 Then ControlSend("Enter", "", "TEdit2",$data[2] )
    If UBound($data) > 2 Then ControlSend("Enter", "", "TEdit1",$data[3] )
    Send("!S")
    Send("{ENTER}")
WEnd
FileClose($file)
Exit
I sure hope you don't want more help in the future with an attitude like that, and if I'm mistaken on the attitude, take a second to read your ******* post before you hit submit, and see how it would read to you.

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

@ron... what about this

$file = FileOpen("D:\Davy\AutoScripts\enterdata.txt", 0)
Run("D:\Davy\AutoScripts\enterdata\prjenter")
WinWait("Enter")
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
        $data = StringSplit($line ," ")
  ... bla
Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

@ron... what about this

$file = FileOpen("D:\Davy\AutoScripts\enterdata.txt", 0)
Run("D:\Davy\AutoScripts\enterdata\prjenter")
WinWait("Enter")
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
        $data = StringSplit($line ," ")
  ... bla
Oops, I am too tired... This should fix most problems I would think:
$file = FileOpen("D:\Davy\AutoScripts\enterdata.txt", 0)
Run("D:\Davy\AutoScripts\enterdata\prjenter");<< are you not getting an error here?  Or did you not put the actual .exe name?
WinWait("Enter")
$Count = 1
While 1
    $line = FileReadLine($file, $Count)
    If @error = -1 Then ExitLoop
    $data = StringSplit($line ," ")
    If IsArray($data) Then
        If UBound($data) - 1 > 0 Then ControlSend("Enter", "", "TEdit3",$data[1] )
        If UBound($data) - 1 > 1 Then ControlSend("Enter", "", "TEdit2",$data[2] )
        If UBound($data) - 1 > 2 Then ControlSend("Enter", "", "TEdit1",$data[3] )
    EndIf
    $Count = $Count + 1
    Send("!S")
    Send("{ENTER}")
WEnd
FileClose($file)
ExitoÝ÷ ØGb´Z+uiû^®Ø^.اna¦-"ØbAÝiÙ²µë-·_W¢Ø^{¦¦W¬¶)eßqÝĽéÛzÛ^­«­¢+ØÀÌØí¥±ô¥±=Á¸ ÅÕ½ÐíèÀäÈíÙäÀäÈíÕѽMÉ¥ÁÑÌÀäÈí¹ÑÉѹÑáÐÅÕ½Ðì°À¤)IÕ¸ ÅÕ½ÐíèÀäÈíÙäÀäÈíÕѽMÉ¥ÁÑÌÀäÈí¹ÑÉÑÀäÈíÁÉ©¹ÑÈÅÕ½Ðì¤ì±Ðì±ÐìÉå½Ô¹½ÐÑÑ¥¹¸ÉɽȡÉü=È¥å½Ô¹½ÐÁÕÐÑ¡ÑÕ°¹á¹µü)]¥¹]¥Ð ÅÕ½Ðí¹ÑÈÅÕ½Ðì¤(ÀÌØí
½Õ¹ÐôÄ)]¡¥±Ä($ÀÌØí±¥¹ô¥±I1¥¹ ÀÌØí¥±°ÀÌØí
½Õ¹Ð¤(%%ÉɽÈô´ÄQ¡¸á¥Ñ1½½À($ÀÌØíÑôMÑÉ¥¹MÁ±¥Ð ÀÌØí±¥¹°ÅÕ½ÐìÅÕ½Ðì¤(%%%ÍÉÉä ÀÌØíѤQ¡¸($%½ÈÀÌØí¥½Õ¹ÐôÄQ¼Ì($$%
½¹Ñɽ±M¹ Ìäí¹ÑÈÌäì°ÌäìÌäì°ÌäíQ¥ÐÌäìµÀì Ì´ÀÌØí¥½Õ¹Ð¤°ÀÌØíÑlÀÌØí¥½Õ¹Ñt¤($%9áÐ(%¹%($ÀÌØí
½Õ¹ÐôÀÌØí
½Õ¹Ð¬Ä(%M¹ ÅÕ½ÐìÌÌíLÅÕ½Ðì¤(%M¹ ÅÕ½Ðíí9QIôÅÕ½Ðì¤)]¹)¥±
±½Í ÀÌØí¥±¤)á¥Ð
Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0