Sign in to follow this  
Followers 0
sqa

how to skip few lines of code during the run

34 posts in this topic

I have something like 900 lines of code and during its testing I don't want to run all of them every time, but skip some.

Let say to execute lines 1-100 and then to skip to 500-...

In VB I would use GOTO, but how can I do the same in AutoIt?

I can try to comment these lines 101-499, but is there something else?

Thanks

Share this post


Link to post
Share on other sites



Group your code into Functions, and then call the functions as needed. The help file has an entire section on this.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

satanttin, the OP is asking about the equivalent to a GOTO statement. Your response makes no sense.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

And deleting own BS post doesn't make more sense.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

I can try to comment these lines 101-499, but is there something else?

If you do want the comment these lines you can use these statements

#cs
MsgBox(0,0,1)
MsgBox(0,0,2)
#ce

Share this post


Link to post
Share on other sites

Block Comment or Uncomment
If you are using SciTE, you can highlight the code you want to comment out, then go to "Edit" menu and press "Block Comment or Uncomment", or ctrl+Q.  Or, you could use "Box Comment".


Box Comment (under SciTes "Edit menu)
Initally "Box Comment" produced an error message about the variables "comment.box.start.au3", "comment.box.middle.au3", and "comment.box.end.au3", not being declared.

For "Box Comment" to work, I had to "Open Global Options File" under SciTe's "Options" menu. And in the SciTeGlobal.properties file change from "strip.trailing.spaces=1" to "strip.trailing.spaces=0" and then saved the file.

Then, under SciTe's  "Options" menu pressed "Open au3.properties" to open the au3.properties file. In this file I added a space after the equals sign in this line "comment.box.middle.au3=" and then saved this file.

Having tested that "Box Comment" now works, I change "strip.trailing.spaces" back to equal "1", and re-saved the SciTeGlobal.properties file.
 

1 person likes this

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

You could slightly modify your script (only in test version) and add an "external" Switch construct in this way:

Global $GOTO = 0
Switch $GOTO
    Case 0
        ; your whole script goes between these two lines
        ; ------------ start of your script ------------

        MsgBox(0,"", "Good morning")

        $goto = 150     ;                             | <-- insert this 2 lines to simulate GOTO 150
        ContinueCase ;                                |      this will jump to  case 150

    ; Case 50
        MsgBox(0,"", "Good Afternoon")
    ; Case 100
        MsgBox(0,"", "Good Evening")

    Case 150 ;                                        | <-- uncomment this to jump here
        MsgBox(0,"", "What are you still doing up?")

        ; ------------- end of your script -------------
EndSwitch

then move the pair $goto 150 - ContinueCase and Case 150 where you want to jump

P.S.
just an idea
(I post even if I do not like it :puke: )

Edited by PincoPanco
1 person likes this

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

Hello there !

I think i'm stupid :)

@PincoPanco, I try to use your example "$GOTO"

I want to "switch" between section. 

Here is a very simple example, but it does not work :

Global $GOTO = 0
Switch $GOTO
Case 0
If FileExists("C:\Bitlocker.txt") Then
$GOTO = 100
Else
$GOTO = 200
ContinueCase
EndIf


Case 100
MsgBox(1, "1", "Case 100")
$GOTO = 300
Case 200
MsgBox(1, "1", "Case 200")
$GOTO = 400
Exit
Case 300
MsgBox(1, "1", "Case 300")
Case 400
MsgBox(1, "1", "Case 400")


EndSwitch

I know this example does not make sens, but for my need the goal is the same.

An idea ?

Thanks!

Share this post


Link to post
Share on other sites

DraGula,

I strongly suggest you learn how to structure your code so that you do not need appalling workarounds like that. Everyone finds losing GOTO a bit difficult when they first encounter a language that did not use it, but learning how to write code that does not use it is well worth it. Trust me, your code becomes much clearer and easier to debug when you do. ;)

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

DraGula,

I strongly suggest you learn how to structure your code so that you do not need appalling workarounds like that. Everyone finds losing GOTO a bit difficult when they first encounter a language that did not use it, but learning how to write code that does not use it is well worth it. Trust me, your code becomes much clearer and easier to debug when you do. ;)

M23

 

Ok... I understanding that GOTO is not a good solution :/

So, I guess the solution for me is to use while and function, right ?

DraGula

Share this post


Link to post
Share on other sites

DraGula,

 

I guess the solution for me is to use while and function, right ?

Exactly. Once you get the hang of it you will wonder how on earth you ever managed to code any other way - your code becomes modular and much easier to debug that a whole mess of GOTO spaghetti. :)

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

GOTO - the bad practice that just will not die :rip:


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

ha "GOTO spaghetti", that's funny

I strongly agree with Melba23,

(it was just a crazy mental experiment),
in addition after testing it,  I see that it does not work (because the switch expression is valuated only once at start of construct) sorry DraGula .

Anyway, why this other "select" construct does not work as it should?

Global $GOTO = 0
Select
    Case $GOTO = 0
        MsgBox(0, "", "case 0 $goto=" & $GOTO)
        $GOTO = 150
        ContinueCase
    Case $GOTO = 50
        MsgBox(0, "", "case 50 $goto=" & $GOTO)
        ContinueCase
    Case $GOTO = 100
        MsgBox(0, "", "case 100 $goto=" & $GOTO)
        ContinueCase
    Case $GOTO = 150
        MsgBox(0, "", "case 150 $goto=" & $GOTO)
        ContinueCase
    Case Else
        MsgBox(0, "", "case else $goto=" & $GOTO)
EndSelect

all the case are executed, ?? why?


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

A: You probably should have created your own thread rather than hijacking this one.

B: You are telling it to ContinueCase within each statement, what did you expect it to do? Change $GOTO to 49, and you'll see it drops down to the Case Else statement.

Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

A: You probably should have created your own thread rather than hijacking this one.

B: You are telling it to ContinueCase within each statement, what did you expect it to do? Change $GOTO to 49, and you'll see it drops down to the Case Else statement.

 

A: many thanks for the advice

B: the problem arise if I change the $goto variable within the select


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

There is valid uses for Goto in other languages as for example, functions in command scripts. Just because some make spaghetti code does not mean that everyone does.

This example command script calls a label that acts as a function and it can return a value. Goto can also be used to jump past comments.

@echo off
goto :start
:: comments
:: comments
:start
echo testing a function
call :function parameter1
echo return value: "%result%"
pause
goto :eof

:function
    setlocal
    echo function passed: "%1"
    set return=%1
    endlocal & set result=%return%
goto :eof

Goto can be used well or it can be made to look like spaghetti. :)

B: the problem arise if I change the $goto variable within the select

ContinueCase ignores the following Case statement and runs the code after the Case statement.

$case = 1
Select
    Case $case = 1
        ContinueCase
    Case $case = 2
        MsgBox(0, 'test', $case)
EndSelect

You will see the MsgBox with a 1 in it. :)

Share this post


Link to post
Share on other sites

......

 

ContinueCase ignores the following Case statement and runs the code after the Case statement.

$case = 1
Select
    Case $case = 1
        ContinueCase
    Case $case = 2
        MsgBox(0, 'test', $case)
EndSelect

You will see the MsgBox with a 1 in it. :)

 

yes, I have seen, thanks MHz

I thought ContinueCase continue to the next Case rather than skip it.


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

PincoPanco,

 

I thought ContinueCase continue to the next Case rather than skip it.

It does - but it runs the code within it, not the Case comparison itself. ;)

M23

Edit: I have amended the Help file text to make this (I hope) clearer:

 

"Normally in a Select or Switch structure, the code within each Case block ends when the next Case statement is encountered. Executing ContinueCase tells AutoIt to stop executing the code within the current Case block and start executing the code within the next Case block. AutoIt does not evaluate the next Case comparison statement - only the code inside the block is run."

Edited by Melba23

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

PincoPanco,

 

It does - but it runs the code within it, not the Case comparison itself. ;)

M23

 

? mysterious ...


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

PincoPanco,

See my edit above. :)

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

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