Jump to content

Stuck in an Do or If loop


Mellon
 Share

Recommended Posts

This was supposed to be a quick and dirty program to complete a one off project. It hasn't been quick.

I have a list of vessel names. These vessel have brought our software and we need to make sure that they are offered an upgrade to a regulatory module we sell.

The program should.

1) Get the name of the vessel from a file on the local machine.

2) Loop through a file text file (purchased.txt) until to comes to the last entry, searching for the word Dealer.

3) Add the vessel and Dealer name to a third file

4) Close the vessel's text file.

5) Start over again at 1 from the next vessel

This works splendidly for the first vessel on the list. However, it seems to get stuck in the Do loop. The information never gets written to file and first purchased.txt file never gets closed.

Is "until @error=-1" valid?

While 1
    
    $VesselName=FileReadLine($Get_Vessel_Name)
    $VesselPath=$customerdatalocation & $VesselName &"\Purchased.txt"
    ;Loop until you reach the end of the File
    
    $Dothefile=Fileopen($Vesselpath,0)
    GUICtrlSetData ( $Label1 , $Vesselpath)
    Do
        
        $LookforLastDealer=FileReadLine($DotheFile)
        $whoisthedeal=StringInStr($LookforLastDealer,"Dealer")
        
        if $Whoisthedeal<> 0 Then
            $Thedealer=$LookforLastDealer
            
            ;$Whoisthedeal=0
            $thestatus=@error
            msgbox(1,$Whoisthedeal, $Thestatus)
        EndIf
    until @error=-1
    msgbox(1,"2", $Thedealer)
    $Whatthefuck=FileWrite($Vesselwithdealer,$VesselName&" "& $Thedealer)
    fileclose($Dothefile)
WEnd
Link to comment
Share on other sites

@error is a value used by all autoit functions. Anytime you call any autoit function, @error is reset to 0. If your are looking to see if filereadline() has set @error to -1, it must be checked directly after the call.

$LookforLastDealer=FileReadLine($DotheFile)
if @error = -1 then exitloop
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...