Jump to content
Sign in to follow this  
webxt

Read external files

Recommended Posts

Is it possible to read external file (for example www.mypage.com/news.txt) with AutoIT?

Best Regards,

webxt

Share this post


Link to post
Share on other sites

#include <INet.au3>
$s_URL = "http://www.mypage.com/news.txt";

Dim $news[4]
_INetGetSource ($s_URL)
$old = -1

Do 
$temp = Random(1,4,1)
Until $temp <> $old

MsgBox(0, "Random news", $news[$temp])

news.txt conent

$news[1] = "news 1"
$news[2] = "news 2"
$news[3] = "news 3"

What's wrong on this script?

Any help would be apreciated.

Best Regards,

webxt

Edited by webxt

Share this post


Link to post
Share on other sites

You don't even have a $comment variable declared. Are you trying to grab a random line from this text file?

Share this post


Link to post
Share on other sites

Yes, I tried to grab a random line from text file (if is it possible without add the "$news[x]...")

#include <INet.au3>

Dim $news[4]
$news[1] = "news 1"
$news[2] = "news 2"
$news[3] = "news 3"
$old = -1

Do 
$temp = Random(1,4,1)
Until $temp <> $old

MsgBox(0, "Random news", $news[$temp])

^example that works

Edited by webxt

Share this post


Link to post
Share on other sites

Well we don't know what your text file looks like, is each line comma seperated? Linefeed seperated? Regardless you are declaring $news array but the contents are actually in $s_URL.

Share this post


Link to post
Share on other sites

news.txt:

$news[1] = "news 1"
$news[2] = "news 2"
$news[3] = "news 3"

but would be greater

news 1
news 2
news 3
Edited by webxt

Share this post


Link to post
Share on other sites

In that case try:

#include <INet.au3>
$s_URL = "http://www.mypage.com/news.txt";

$original = _INetGetSource ($s_URL)

$split = StringSplit($original, @CRLF)

For $X = 1 to $split[0]
ConsoleWrite("News item " & $X & ": " & $split[$X] & @CRLF)
Next

Share this post


Link to post
Share on other sites

Thank you, Weaponx!

A little thing: if I want to show only one random news than exit, what should I do?

Best Regards,

webxt

Edited by webxt

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  

×
×
  • Create New...