Sign in to follow this  
Followers 0
zasxes

Array Issues

8 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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!

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

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

Error is:

if $line[$POS] >= 100 then

If $line^ERROR

Error: Subscript used with non-array variable

Share this post


Link to post
Share on other sites

Like i mentioned in my previous post:

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


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

It looks like maybe it should be $Split[$Pos]

Also since it is going to a function you might want to make $Split a Global variable I think.

red

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

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.

Share this post


Link to post
Share on other sites

Ok the studies.txt file has a list of say 20 different webs sites. If at any point I get over 100 server not found errors for an indidvidual site I want it to pop up a msg box.

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