Jump to content
Sign in to follow this  
Appie78

For....Next

Recommended Posts

Appie78

Hi Guys,

Is it possible to change the value of $i while the loop is running?

For $i = 1 to 10 Step 3

Thanks


Electron microscopes rule!!!

Share this post


Link to post
Share on other sites
Authenticity

Yup, but not the end case. For example if the loop is processing until i is equal to the UBound of an array then resizing this array won't change the amount of loops. For this kind of task there is While..WEnd or Do...Until

Share this post


Link to post
Share on other sites
Melba23

Pokerface,

Have you tried?

M23

P.S. Yes.


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Appie78

CODE
Func Recall()

$Recall1 = FileOpen("c:\program files\scan sample\Positions.log", 0); Laad het bestand met de posities.

MsgBox(0,"", $Recall1)

If $Recall1 = -1 Then

Return MsgBox(0, "Error", "No file with positions.")

Exit

EndIf

$Line = FileRead($Recall1); Lees het file uit.

$AvArray = StringSplit($Line, ";", 1); Zet de waardes in een Array en scheid ze door de ; weg te halen.

_ArrayTrim($AvArray, 2, 0, 2)

$Tel = UBound($AvArray); tel het aantal posities.

$Coor = $Tel - 2; posities - 2.

If $Coor < 3 Then

Return MsgBox(0, "Custom Service", "No data or corrupted file.")

Exit

EndIf

HotKeySet("{bs}", "BackRecall")

For $q = 1 To $Coor Step 3

$u = $AvArray[$q]

$v = $AvArray[$q + 1]

$w = $AvArray[$q + 2]

WinActivate("Scanning Electron Microscope")

Sleep(200)

ControlClick("Scanning Electron Microscope", "", 89, "left", 1, 20, 20); Stage control10

Sleep(100)

WinActivate("Stage Control")

Sleep(200)

Send("!p")

Send($u)

Send("{Tab}")

Send($v)

Send("{Tab}")

Send($w)

Sleep(1000)

ControlClick("Positioning", "", 1, "left", 1, 20, 20); Verplaats naar positie

Sleep(5000)

If $q = $Coor - 2 Then

MsgBox(0, "Custom Service", "Finished"); Alle posities bekeken

Else

$Msg = MsgBox(1, "Custom Service", "Continue or Cancel?"); Naar de volgende positie of stoppen?

If $Msg = 2 Then

ExitLoop

Else

MsgBox(0, "Custom Service", "Moving to next position", 3); Verplaats naar positie

EndIf

EndIf

Next

HotKeySet("{bs}")

FileClose($Recall1)

EndFunc ;==>Recall

Func BackRecall()

ControlClick("Stage Control", "", 3, "left", 1, 20, 20)

$d = $q - 3

EndIf

MsgBox(0, "", $d)

$a = $AvArray[$d]

$b = $AvArray[$d + 1]

$c = $AvArray[$d + 2]

WinActivate("Scanning Electron Microscope")

Sleep(200)

ControlClick("Scanning Electron Microscope", "", 89, "left", 1, 20, 20); Stage control10

Sleep(100)

WinActivate("Stage Control")

Sleep(200)

Send("!p")

Send($a)

Send("{Tab}")

Send($:P

Send("{Tab}")

Send($c)

Sleep(1000)

ControlClick("Positioning", "", 1, "left", 1, 20, 20); Verplaats naar positie

Sleep(5000)

$q = $q - 3

EndFunc

This is my code, I want to decrease $q by 3.

To set the array to the correct values.


Electron microscopes rule!!!

Share this post


Link to post
Share on other sites
Appie78

Hi James,

If you look at the BackRecall function you'll see I want to decrease $q by 3.

Hoping that the Recall function changes its value.

Cheers.


Electron microscopes rule!!!

Share this post


Link to post
Share on other sites
James

Hi James,

If you look at the BackRecall function you'll see I want to decrease $q by 3.

Hoping that the Recall function changes its value.

Cheers.

:P Well think about it... Increase, "3" and to decrease.... We minus :0 "-3".

For $q = 1 To $Coor Step -3

Edit: Smiley fix :unsure:

Edited by JamesBrooks

Share this post


Link to post
Share on other sites
Appie78

Hi James,

Did you read my code or did you just look at the question at the top?

please read the code maybe you can give me better info. :P

Arnaud


Electron microscopes rule!!!

Share this post


Link to post
Share on other sites
James

Hi James,

Did you read my code or did you just look at the question at the top?

please read the code maybe you can give me better info. :P

Arnaud

Both.

Func Recall()

$Recall1 = FileOpen("c:\program files\scan sample\Positions.log", 0); Laad het bestand met de posities.
MsgBox(0,"", $Recall1)
If $Recall1 = -1 Then
Return MsgBox(0, "Error", "No file with positions.")
Exit
EndIf

$Line = FileRead($Recall1); Lees het file uit.
$AvArray = StringSplit($Line, ";", 1); Zet de waardes in een Array en scheid ze door de; weg te halen.
_ArrayTrim($AvArray, 2, 0, 2)
$Tel = UBound($AvArray); tel het aantal posities.
$Coor = $Tel - 2; posities - 2.

If $Coor < 3 Then
Return MsgBox(0, "Custom Service", "No data or corrupted file.")
Exit
EndIf

HotKeySet("{bs}", "BackRecall")

For $q = 1 To $Coor Step -3

$u = $AvArray[$q]
$v = $AvArray[$q + 1]
$w = $AvArray[$q + 2]

WinActivate("Scanning Electron Microscope")
Sleep(200)
ControlClick("Scanning Electron Microscope", "", 89, "left", 1, 20, 20); Stage control10
Sleep(100)
WinActivate("Stage Control")
Sleep(200)
Send("!p")
Send($u)
Send("{Tab}")
Send($v)
Send("{Tab}")
Send($w)
Sleep(1000)
ControlClick("Positioning", "", 1, "left", 1, 20, 20); Verplaats naar positie
Sleep(5000)

If $q = $Coor - 2 Then
MsgBox(0, "Custom Service", "Finished"); Alle posities bekeken
Else
$Msg = MsgBox(1, "Custom Service", "Continue or Cancel?"); Naar de volgende positie of stoppen?
If $Msg = 2 Then
ExitLoop
Else
MsgBox(0, "Custom Service", "Moving to next position", 3); Verplaats naar positie
EndIf
EndIf

Next

HotKeySet("{bs}")

FileClose($Recall1)

EndFunc;==>Recall

Func BackRecall()

ControlClick("Stage Control", "", 3, "left", 1, 20, 20)

$d = $q - 3

EndIf
MsgBox(0, "", $d)
$a = $AvArray[$d]
$b = $AvArray[$d + 1]
$c = $AvArray[$d + 2]

WinActivate("Scanning Electron Microscope")
Sleep(200)
ControlClick("Scanning Electron Microscope", "", 89, "left", 1, 20, 20); Stage control10
Sleep(100)
WinActivate("Stage Control")
Sleep(200)
Send("!p")
Send($a)
Send("{Tab}")
Send($b)
Send("{Tab}")
Send($c)
Sleep(1000)
ControlClick("Positioning", "", 1, "left", 1, 20, 20); Verplaats naar positie
Sleep(5000)
$q = $q - 3
EndFunc

Share this post


Link to post
Share on other sites
Appie78

Hi James,

I understand your solution but it's not my problem!!!!!

Let me try to explain a bit better.

I've got coordinats (x, y, r) saved in a file, I want to recall these coordinats.

That's where the Recall() comes in. But I want to make it possible to go back 1 position that's where the BackRecall() comes in.

If the position is back by 1 the recall position is doing it's next cycle and continues with the 3rd so the second position is skipped.

I don't want to skip this position so I need to change the For..Next loop.

I hope this clears up my problem.

Thanks


Electron microscopes rule!!!

Share this post


Link to post
Share on other sites
Melba23

Pokerface,

Why not use a 2D array to save your coordinates and avoid all this triple-jumping?

Global $AvArray[n][3]
..
$u = $AvArray[$q][0]
$v = $AvArray[$q][1]
$w = $AvArray[$q][2]

Then you only need to jump one forward/back and the Step value becomes moot.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Appie78

@ James,

The $Step seems to work!!

@ M23

A 2d array may come in handy. Does anybody have an example how to make an 2d array from a file?

Thanks


Electron microscopes rule!!!

Share this post


Link to post
Share on other sites
BrettF
Appie78

@ Brettf

The content of the file are coordinats so only numbers which are seperated by a ;

Thanks


Electron microscopes rule!!!

Share this post


Link to post
Share on other sites
Melba23

Pokerface,

If your coordinates file looks like this:

1-1;1-2;1-3;2-1;2-2;2-3;3-1;3-2;3-3;4-1;4-2;4-3

then this code:

#include <Array.au3>

$sString = FileRead("coords.txt")

ConsoleWrite($sString & @CRLF)

$aCoords_1D = StringSplit($sString, ";")

_ArrayDisplay($aCoords_1D)

Global $aCoords_2D[$aCoords_1D[0] / 3][3]

$k = 1
For $i = 0 To 3
    For $j = 0 To 2
        $aCoords_2D[$i][$j] = $aCoords_1D[$k]
        $k += 1
    Next
Next

_ArrayDisplay($aCoords_2D)

will get it into a 2D array.

Array.au3 is only included to show you the results via _ArrayDisplay - it is not needed for the actual code. You will have to check that the size of the first dimension of your 2D array is correctly set. AutoIt kindly sets the [0] element of the array produced by StringSplit to the number of elements found - so if you are sure that you have only coord-triplets, you just need to divide this number by 3.

You will doubtless have to tweak this a bit to meet your requirements, but I hope the basic principles are clear.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Appie78

Thanks M23,

The 2d array works fine after some adjustments like you sad.

I thought that the $step in For $i = 0 to $Coor Step $step worked but I was mistaking.

I've tried to work with an .Ini file aswell, didn't work.

Does anybody got any suggestions?

Pokerface


Electron microscopes rule!!!

Share this post


Link to post
Share on other sites
BrettF

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  

×