Jump to content

how to skip few lines of code during the run


sqa
 Share

Recommended Posts

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

Link to comment
Share on other sites

  • Moderators

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • 4 weeks later...
  • Moderators

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
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)

Link to comment
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.
 

Link to comment
Share on other sites

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

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Link to comment
Share on other sites

  • 3 weeks later...

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!

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
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

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
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?

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Link to comment
Share on other sites

  • Moderators

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
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

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Link to comment
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. :)

Link to comment
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.

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • Moderators

PincoPanco,

See my edit above. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

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...