Jump to content

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


Recommended Posts

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...

Link to comment
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)

Link to comment
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)

Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...