Jump to content

Array Issues


Recommended Posts

Why isnt this working at line "If $line[$POS] >= 100"

I am trying to add 1 to the array varaiable that coinsides with the line I am reading if there is an error

$LIST="studies.txt"
Dim $a
$a=FileCountLines($LIST )
MsgBox(0, "Message", $a)
Dim $line[$a]

While 1;==>OpenLIST
$LIST = FileOpen("studies.txt", 0)

   $POS=0
   While 1;==>ReadLIST
      $POS=$POS+1
      If OPENLIST() = 1 Then ExitLoop
      OPENSITE()
      Sleep(3000)
      $TITLEX=WinGetTitle("","") 

      If $TITLEX = "Cannot find server - Microsoft Internet Explorer" Then 
         $line[$POS]= $LINE[$POS]+1
      EndIf 
      WinClose($TITLEX)
     If $line[$POS] >= 100 Then;<---------<<Error Here
        MsgBox(0, "Message", "Got here")
     EndIf
   Wend;==>ReadLIST

Wend;==>OpenLIST
; ----------------------------------------------------------------------------
; Func OPENLIST()
; ----------------------------------------------------------------------------

Func OPENLIST()
   $RETURN=0
   $LINE = FileReadLine($LIST)
   If @error = -1 Then 
      FileClose($LIST)
      $RETURN=1
   EndIf
   If $LINE = "" Then 
      $RETURN=1
   EndIf
   
   $SPLIT=StringSplit($LINE,".")
   $LOGNAME=StringTrimLeft($SPLIT[1],7)
   
   If $RETURN=1 Then
      Return( 1)
   Else
      Return( 0)
   EndIf 
   
EndFunc ;==>OPENLIST()

; ----------------------------------------------------------------------------
; Func OPENSITE()
; ----------------------------------------------------------------------------

Func OPENSITE()
   Run('explorer.exe '& $LINE)
   WinWait("classname=IEFrame")
   If Not WinActive("classname=IEFrame","") Then WinActivate("classname=IEFrame","")
   WinWaitActive("classname=IEFrame","")
   WinShow("classname=IEFrame","", @SW_MAXIMIZE)

EndFunc  ;==>OPENSITE
; ----------------------------------------------------------------------------
; Func FileCountLines()
; ----------------------------------------------------------------------------

Func FileCountLines( ByRef $sFilePath, )
 Local $hFile
 Local $iLines

 $hFile = FileOpen($sFilePath, 0)
 If $hFile <> -1 Then
   While 1
     FileReadLine( $hFile )
     If @error = -1 Then ExitLoop
     $iLines = $iLines + 1
   Wend
   FileClose($hFile)
   Return $iLines
 Else
   SetError( 1 )
   Return 0
 EndIf
EndFunc
Link to comment
Share on other sites

What error message? Do you get an "index out of bounds" error?

You don't appear to check that $POS >= 0 And $POS < $a

What is supposed to happen after the last element of your $line[] array is read?

Maybe try

$POS= -1
  While $POS < $a;==>ReadLIST
     $POS=$POS+1;first element is zero
Edited by CyberSlug
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

  • Developers

what are you testing with this statement: If $line[$POS] >= 100

on line 5 you dim the array:Dim $line[$a]

on line 34 you read a record into this var: $LINE = FileReadLine($LIST)

this doens't create an array!

so you probably get an error : subscript used with non-Array variable ??

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

Like i mentioned in my previous post:

I think the $line contains the record and isn't an Array.....

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

While 1;==>ReadLIST
     $POS=$POS+1

You need to stop the loop before it goes over the amount of array elements.

While $POS<$a;==>ReadLIST  or something like this
     $POS=$POS+1

edit NM, I can't make out much of anything going on with $LINE and $line[]

Functions use a non array variable $line

Main script uses array $line[]

I usually use different variables for arrays and normal variables, so this got too confusing for me :whistle:

Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

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