Sign in to follow this  
Followers 0
gempie

Messed up loop

7 posts in this topic

Hi all,

i always have great difficulty in making a loop like the one down below work correctly. It always takes me a long time to work things out. So can anyone please explain me the rules?

this is my code, it goes wrong at the point where $acroniem = "Thallium" is. I know i need to put an endif statment after $dosis = "550" but when i do so the loop exits??

[/code]
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.2.4.9
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <file.au3>
Dim $aRecords
Dim $acroniem
Dim $dosis
Dim $product

$file = FileOpen("patlist.txt", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open patlist.txt.")
    Exit
EndIf

;Read in 1 character at a time until the EOF is reached
While 1
   $chars = FileRead($file)
    If @error = -1 Then ExitLoop
  ;MsgBox(0, "Char read:", $chars)
   $strip=StringStripWS($chars,2)
Wend
;MsgBox(0, "Strip read:", $strip)
FileClose($file)
$file2 = FileOpen("patlist.txt", 2)
FileWrite($file2, $strip)
FileClose($file2)
Run(@ComSpec & " /c excel.exe c:\AanvraagRFWesteinde2.xls", "C:\PROGRA~1\MICROS~2\OFFICE11", @SW_HIDE)
WinWaitActive("Microsoft Excel","AanvraagRFWesteinde2.xls")

sleep (500)
If Not _FileReadToArray("patlist.txt",$aRecords) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf

For $x = 1 to $aRecords[0]
    $split=StringSplit($aRecords[$x], @TAB)
   ;Msgbox(0,'Record:' & $x, $aRecords[$x])
    if $split[5] = "V" then $split[5]= "mw."
    if $split[5] = "M" then $split[5]= "hr."
;if $split[4]-$date=<18 then $split[5]= "kind"  
    
    if $split[2] = "SKELET" then $split[2]= "skelet"
    if $split[2] = "201TL" then $split[2]= "hersenen"
    if $split[2] = "67GA" then $split[2]= "??"
    if $split[2] = "DAT" then $split[2]= "??"
    if $split[2] = "EF2" then $split[2]= "ejectiefractie"
    if $split[2] = "GAL" then $split[2]= "gal"
    if $split[2] = "HIG2" then $split[2]= "??"
    if $split[2] = "I123" then $split[2]= "??"
    if $split[2] = "I131UP" then $split[2]= "??"
    if $split[2] = "IBZM" then $split[2]= "IBZM-scan"
    if $split[2] = "LEUCOS" then $split[2]= "??"
    if $split[2] = "LEVER" then $split[2]= "??"
    if $split[2] = "LONG" then $split[2]= "longperfusie"
    if $split[2] = "LYMF2" then $split[2]= "??"
    if $split[2] = "MAAG1" then $split[2]= "??"
    if $split[2] = "MECKEL" then $split[2]= "??"
    if $split[2] = "MIBG2" then $split[2]= "??"
    if $split[2] = "MIBI" then $split[2]= "bijschildklier"
    if $split[2] = "MYOCAR" then $split[2]= "myocard"
    if $split[2] = "NIER" then $split[2]= "nieren"
    if $split[2] = "PET" then $split[2]= "??"
    if $split[2] = "RENOGR" then $split[2]= "renografie"
    if $split[2] = "SN" then $split[2]= "sentinel"
    if $split[2] = "SN3" then $split[2]= "??1dags"
    if $split[2] = "SN4" then $split[2]= "??melanoom"
    if $split[2] = "SOMATO" then $split[2]= "??"
    if $split[2] = "TC99M" then $split[2]= "schildklier"
    if $split[2] = "TCERY" then $split[2]= "??"
    if $split[2] = "BHQUAD" then $split[2]= "??quadramet"
    if $split[2] = "BHSR89" then $split[2]= "strontium"
    if $split[2] = "BHP32" then $split[2]= "??phospor"


msgbox(0,"product",$product)
if $split[2] = "skelet" then $product = "99mTc-oxidronaat"
    $acroniem = "HDP"
    $dosis = "550"
            
if $split[2] = "hersenen" then $product = "201TL-chloride"
    $acroniem = "Thallium"
    $dosis = "125"

    msgbox(0,"$split[2]",$split[2])
    msgbox(0,"product",$product)
    msgbox(0,"product",$acroniem)
    msgbox(0,"product",$dosis)
;Msgbox(0,'split', $split[5])
;Msgbox(0,'split', $split[3])
;Msgbox(0,'split', $split[4])
;Msgbox(0,'split', $split[2])
;Msgbox(0,'split', $split[1])

send("{left}")
send($split[5])
send("{tab}")
send($split[3])
send("{tab}")
send($split[4])
send("{tab}")
send($split[2])
send("{tab}")
msgbox(0,"na split2",$product)
send ($product)
send("{tab}")
send ($acroniem)
send("{tab}")
send ($dosis)
send("{tab}")
send($split[1])
send("{down}")
send("{left 6}")

Next

[code]

Share this post


Link to post
Share on other sites



Download the full version of SciTE and run Tidy (ctrl-t) and Syntax Check (ctrl-F5) on it. Fix the errors you get from that --> THEN post the results.

Fixing the problems found by the automated checks may fix your other problems. You really shouldn't ever post code until you have a least taken the steps above.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Download the full version of SciTE and run Tidy (ctrl-t) and Syntax Check (ctrl-F5) on it. Fix the errors you get from that --> THEN post the results.

Fixing the problems found by the automated checks may fix your other problems. You really shouldn't ever post code until you have a least taken the steps above.

:)

Oke, done so. Script still looks accectly the smame though!!

[/code]

#cs ----------------------------------------------------------------------------
    
    AutoIt Version: 3.2.4.9
    Author:      myName
    
    Script Function:
    Template AutoIt script.
    
#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <file.au3>
Dim $aRecords
Dim $acroniem
Dim $dosis
Dim $product

$file = FileOpen("patlist.txt", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open patlist.txt.")
    Exit
EndIf

;Read in 1 character at a time until the EOF is reached
While 1
    $chars = FileRead($file)
    If @error = -1 Then ExitLoop
;MsgBox(0, "Char read:", $chars)
    $strip = StringStripWS($chars, 2)
WEnd
;MsgBox(0, "Strip read:", $strip)
FileClose($file)
$file2 = FileOpen("patlist.txt", 2)
FileWrite($file2, $strip)
FileClose($file2)
Run(@ComSpec & " /c excel.exe c:\AanvraagRFWesteinde2.xls", "C:\PROGRA~1\MICROS~2\OFFICE11", @SW_HIDE)
WinWaitActive("Microsoft Excel", "AanvraagRFWesteinde2.xls")

Sleep(500)
If Not _FileReadToArray("patlist.txt", $aRecords) Then
    MsgBox(4096, "Error", " Error reading log to Array   error:" & @error)
    Exit
EndIf

For $x = 1 To $aRecords[0]
    $split = StringSplit($aRecords[$x], @TAB)
;Msgbox(0,'Record:' & $x, $aRecords[$x])
    If $split[5] = "V" Then $split[5] = "mw."
    If $split[5] = "M" Then $split[5] = "hr."
;if $split[4]-$date=<18 then $split[5]= "kind"
    
    If $split[2] = "SKELET" Then $split[2] = "skelet"
    If $split[2] = "201TL" Then $split[2] = "hersenen"
    If $split[2] = "67GA" Then $split[2] = "??"
    If $split[2] = "DAT" Then $split[2] = "??"
    If $split[2] = "EF2" Then $split[2] = "ejectiefractie"
    If $split[2] = "GAL" Then $split[2] = "gal"
    If $split[2] = "HIG2" Then $split[2] = "??"
    If $split[2] = "I123" Then $split[2] = "??"
    If $split[2] = "I131UP" Then $split[2] = "??"
    If $split[2] = "IBZM" Then $split[2] = "IBZM-scan"
    If $split[2] = "LEUCOS" Then $split[2] = "??"
    If $split[2] = "LEVER" Then $split[2] = "??"
    If $split[2] = "LONG" Then $split[2] = "longperfusie"
    If $split[2] = "LYMF2" Then $split[2] = "??"
    If $split[2] = "MAAG1" Then $split[2] = "??"
    If $split[2] = "MECKEL" Then $split[2] = "??"
    If $split[2] = "MIBG2" Then $split[2] = "??"
    If $split[2] = "MIBI" Then $split[2] = "bijschildklier"
    If $split[2] = "MYOCAR" Then $split[2] = "myocard"
    If $split[2] = "NIER" Then $split[2] = "nieren"
    If $split[2] = "PET" Then $split[2] = "??"
    If $split[2] = "RENOGR" Then $split[2] = "renografie"
    If $split[2] = "SN" Then $split[2] = "sentinel"
    If $split[2] = "SN3" Then $split[2] = "??1dags"
    If $split[2] = "SN4" Then $split[2] = "??melanoom"
    If $split[2] = "SOMATO" Then $split[2] = "??"
    If $split[2] = "TC99M" Then $split[2] = "schildklier"
    If $split[2] = "TCERY" Then $split[2] = "??"
    If $split[2] = "BHQUAD" Then $split[2] = "??quadramet"
    If $split[2] = "BHSR89" Then $split[2] = "strontium"
    If $split[2] = "BHP32" Then $split[2] = "??phospor"


    MsgBox(0, "product", $product)
    If $split[2] = "skelet" Then $product = "99mTc-oxidronaat"
    $acroniem = "HDP"
    $dosis = "550"
    
    If $split[2] = "hersenen" Then $product = "201TL-chloride"
    $acroniem = "Thallium"
    $dosis = "125"

    MsgBox(0, "$split[2]", $split[2])
    MsgBox(0, "product", $product)
    MsgBox(0, "product", $acroniem)
    MsgBox(0, "product", $dosis)
;Msgbox(0,'split', $split[5])
;Msgbox(0,'split', $split[3])
;Msgbox(0,'split', $split[4])
;Msgbox(0,'split', $split[2])
;Msgbox(0,'split', $split[1])

    Send("{left}")
    Send($split[5])
    Send("{tab}")
    Send($split[3])
    Send("{tab}")
    Send($split[4])
    Send("{tab}")
    Send($split[2])
    Send("{tab}")
    MsgBox(0, "na split2", $product)
    Send($product)
    Send("{tab}")
    Send($acroniem)
    Send("{tab}")
    Send($dosis)
    Send("{tab}")
    Send($split[1])
    Send("{down}")
    Send("{left 6}")

Next
[code]

Share this post


Link to post
Share on other sites

What do you mean it "goes wrong"? Be specfic please. Include output to the console?

Does this help:

If $split[2] = "skelet" Then
        $product = "99mTc-oxidronaat"
        $acroniem = "HDP"
        $dosis = "550"
    ElseIf $split[2] = "hersenen" Then
        $product = "201TL-chloride"
        $acroniem = "Thallium"
        $dosis = "125"
    Else
        ;Create a default case here
    EndIf

IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]

Share this post


Link to post
Share on other sites

Hey,

thnx for reply.

the problem is any endif or else or elseif statement i put in there stops the for...next loop.

If i loop it like it is i get:

[/code]
MsgBox(0, "product", $product)
    If $split[2] = "skelet" Then $product = "99mTc-oxidronaat"
    $acroniem = "HDP"
    $dosis = "550"
;here should be an endif

    $split[2] = "hersenen" Then $product = "201TL-chloride"
    $acroniem = "Thallium"
    $dosis = "125"
;here should be an endif as wel
;result
    MsgBox(0, "$split[2]", $split[2]);skelet should be skelet
    MsgBox(0, "product", $product);99mTc-oxidronaat should be 99mTc-oxidronaat
    MsgBox(0, "product", $acroniem);Thallium should be HDP
    MsgBox(0, "product", $dosis);125 should be 550
[code]

i can see where it goes wrong (i need to put in the endif) but if i do so it ends the for loop somehow.

So the first run should give me:

$split[2] = "skelet"

$product = "99mTc-oxidronaat"

$acroniem = "HDP"

$dosis = "550"

the second run should give me:

$split[2] = "hersenen"

$product = "201TL-chloride"

$acroniem = "Thallium"

$dosis = "125"

thnx for trying to help me out here!

Share this post


Link to post
Share on other sites

i not quit sure i understand you but else goes before the endif.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I commented on Tidy/Syntax check based on your statements about missing 'EndIf'. You seem to have a more basic usage problem:

the problem is any endif or else or elseif statement i put in there stops the for...next loop.

If i loop it like it is i get:

MsgBox(0, "product", $product)
    If $split[2] = "skelet" Then $product = "99mTc-oxidronaat"
    $acroniem = "HDP"
    $dosis = "550"
;here should be an endif

    $split[2] = "hersenen" Then $product = "201TL-chloride"
    $acroniem = "Thallium"
    $dosis = "125"
;here should be an endif as wel
;result
    MsgBox(0, "$split[2]", $split[2]);skelet should be skelet
    MsgBox(0, "product", $product);99mTc-oxidronaat should be 99mTc-oxidronaat
    MsgBox(0, "product", $acroniem);Thallium should be HDP
    MsgBox(0, "product", $dosis);125 should be 550

i can see where it goes wrong (i need to put in the endif) but if i do so it ends the for loop somehow.

So the first run should give me:

$split[2] = "skelet"

$product = "99mTc-oxidronaat"

$acroniem = "HDP"

$dosis = "550"

the second run should give me:

$split[2] = "hersenen"

$product = "201TL-chloride"

$acroniem = "Thallium"

$dosis = "125"

thnx for trying to help me out here!

Try them this way:

If $split[2] = "skelet" Then
    $product = "99mTc-oxidronaat"
    $acroniem = "HDP"
    $dosis = "550"
ElseIf $split[2] = "hersenen" Then
    $product = "201TL-chloride"
    $acroniem = "Thallium"
    $dosis = "125"
EndIf

If I understood correctly, the problem was your use of a single-line If/Then format, when you needed a muti-line.

When you do If/Then with a multi-line conditional part, no part of that goes on the same line with 'Then'.

There should only be code after 'Then' if you can put the conditional statement entirely on the one line.

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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