Sign in to follow this  
Followers 0
Jury

Why doesn't this work?

7 posts in this topic

Please - what's wrong here - I copied these two parts from the examples but it doesn't work. I get this error:

C:\Program Files\AutoIt3\Examples\InetGet_ju.au3 (25) : ==> Expected a "=" operator in assignment statement.:

$array[$x] = StringRegExp($line, 'HTML', 2)

$array^ ERROR

-----------------------------------------

$file = FileOpen("C:\foo.html", 0)

; Check if file opened for reading OK

If $file = -1 Then

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

Exit

EndIf

$x = 1

While 1

$line = FileReadLine($file)

$x += 1

If @error = -1 Then ExitLoop

$array[$x] = StringRegExp($line, 'HTML', 2)

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

Wend

FileClose($file)

for $i = 0 to UBound($array) - 1

msgbox(0, "RegExp Test with Option 2 - " & $i, $array[$i])

Next

------------------------------------

Thanks for any pointers,

Jury

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You have to declare $array as an array at the start of your script.

Please use codeboxes when displaying code (preferably autoit codeboxes).

Edited by Hawkwing

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Share this post


Link to post
Share on other sites

You have to declare $array as an array at the start of your script.

Please use codeboxes when displaying code (preferably autoit codeboxes).

Hawkwing,

Thanks - can't find anything about codeboxes I'll try

 
- now it compiles and ends with +>18:15:59 AutoIt3Wrapper Finished but still no msgbox appears.

Dim $array[10]


InetGet("http://www.publications.parliament.uk/pa/ld/ldjudgmt.htm", "C:\foo.html")

$file = FileOpen("C:\foo.html", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
$x = 1
While 1
    $line = FileReadLine($file)
    $x += 1
    If @error = -1 Then ExitLoop
$array = StringRegExp($line, 'HTML', 2)
    ;MsgBox(0, "Line read:", $line)
Wend

for $i = 0 to UBound($array) - 1
    msgbox(0, "RegExp Test with Option 2 - " & $i, $array[$i])
Next
FileClose($file)

Share this post


Link to post
Share on other sites

Perhaps that example was for a previous version, it doesn't seem to be getting to the while loop.

btw, it used to be that you had to use to have a scrolling codebox, but I guess does that now. You can use [autoit][/autoit] to have the code colored like it is in SciTE, making it much easier to read.


The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Share this post


Link to post
Share on other sites

This line will override the Array each time a record is read, so that means you will only get the result of the last record.

$array = StringRegExp($line, 'HTML', 2)

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

#6 ·  Posted (edited)

Perhaps that example was for a previous version, it doesn't seem to be getting to the while loop.

Hmm, must have been something I did, it's working now.

Try this

#include<file.au3>

Dim $array[_FileCountLines("C:\foo.html") + 1]

InetGet("http://www.publications.parliament.uk/pa/ld/ldjudgmt.htm", "C:\foo.html")

$file = FileOpen("C:\foo.html", 0)

;Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
$x = 1
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    $array[$x] = StringRegExp($line, 'HTML', 2)
    $x += 1
Wend

for $i = 0 to UBound($array) - 1
    msgbox(0, "RegExp Test with Option 2 - " & $i, $array[$i])
Next
FileClose($file)

Edit: That's an autoit codebox, much easier to read :D (well, unless the code isn't autoit)

Edited by Hawkwing

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Share this post


Link to post
Share on other sites

Thanking you Hawkwing and Jos now it works,

Cheers,

jury

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