Sign in to follow this  
Followers 0
JamesWilcox

How do you open a file read its contents and pass the contents to a control?

6 posts in this topic

How do you open a file read its contents and pass the contents to a control?

Say in the file you had: description, frequency, multiplier

For example: signal, 110, 3.0

And you want to send it to a control that has three fields: description, frequency, multiplier

You decide to open a file and read the contents and send the contents to the control to fill in these three fields.

How do you do that? Please help...

Share this post


Link to post
Share on other sites



Start in the Help file.. Look for

FileOpen

FileReadLine

ControlSetText

Or have a try in the Autoit1-2-3 in my signature


Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit

Share this post


Link to post
Share on other sites

I did this:

; Script Start - Add your code below here

$file = FileOpen("test.txt", 0)

; Check if file opened for reading OK

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

; Read in lines of text until the EOF is reached

While 1

$line = FileReadLine($file)

If @error = -1 Then ExitLoop

ControlSetText ( "title", "text", controlID, "new text" [, flag] ); what do I put here to put data read from file into the control?

MsgBox(0, "Line read:", $line)

Wend

FileClose($file)

Share this post


Link to post
Share on other sites

I did this:

; Script Start - Add your code below here

$file = FileOpen("test.txt", 0)

; Check if file opened for reading OK

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

; Read in lines of text until the EOF is reached

While 1

$line = FileReadLine($file)

If @error = -1 Then ExitLoop

ControlSetText ( "title", "text", controlID, "new text" [, flag] ); what do I put here to put data read from file into the control?

MsgBox(0, "Line read:", $line)

Wend

FileClose($file)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Try this. I added ControlSend() in for you since you are doing line by line and added 2nd ControlSend() without raw mode for @CRLF.

; Script Start - Add your code below here
$file = FileOpen("test.txt", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

; Read in lines of text until the EOF is reached
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    ControlSend('title', 'text', 'ControlID', $line, 1)
    ControlSend('title', 'text', 'ControlID', @CRLF)
    MsgBox(0, "Line read:", $line)
Wend

FileClose($file)

:whistle:

Edited by MHz

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