How to write code in several lines

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
pantik
Junior Coder
Posts: 45
Joined: Sun Dec 13, 2009 5:52 pm

How to write code in several lines

Post by pantik » Mon Oct 05, 2015 1:14 pm

After a lot of searchs for some days i cound not find how to splite a code line.How can i continue code in the next line?

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Re: How to write code in several lines

Post by armsys » Mon Oct 05, 2015 1:39 pm

Show us a real example.

pantik
Junior Coder
Posts: 45
Joined: Sun Dec 13, 2009 5:52 pm

Re: How to write code in several lines

Post by pantik » Mon Oct 05, 2015 3:21 pm

Code: Select all

 
Srt>Captura_Haystack
ScreenCapture>Captura_Haystack_var_1,Captura_Haystack_var_2,Captura_Haystack_var_3,Captura_Haystack_var_4,%CAPTURAS_DIR%\%Captura_Haystack_var_5%.bmp
      if>SCREENCAP_RESULT<>0
        GoSub>Continuar,"ScreenCapture" failed%crlf%SCREENCAP_RESULT: %SCREENCAP_RESULT%%crlf%Captura: %Captura_Haystack_var_5%.bmp
      endif
END>Captura_Haystack
When i have to use this subrutine and i am including 5 arguments the line is too much long.

Code: Select all

GoSub>Captura_Haystack,BB_PANEL_DER_INI_X,BB_PANEL_DER_INI_Y,BB_PANEL_DER_FIN_X,BB_PANEL_DER_FIN_Y,temp_Captura_Verificable
So i am loking something like

Code: Select all

GoSub>Captura_Haystack,BB_PANEL_DER_INI_X,_
BB_PANEL_DER_INI_Y,_
BB_PANEL_DER_FIN_X,_
BB_PANEL_DER_FIN_Y,_
temp_Captura_Verificable

hagchr
Automation Wizard
Posts: 331
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: How to write code in several lines

Post by hagchr » Mon Oct 05, 2015 4:57 pm

Hi, For the SRT, to avoid the long names, I would typically add a couple of lines with meaningful names so it is clear what is happening, also use local scope to the SRT, ie something like:

Code: Select all

SRT>Captura_Haystack
Let>LOCALVARS=1

Let>tmp=Captura_Haystack_var
Let>x1=%tmp%_1
Let>y1=%tmp%_2
Let>x2=%tmp%_3
Let>y2=%tmp%_4
Let>file=%tmp%_5

ScreenCapture>x1,y1,x2,y2,SCFile
If>SCREENCAP_RESULT<>0
    Let>Message="ScreenCapture" failed%crlf%SCREENCAP_RESULT: %SCREENCAP_RESULT%%crlf%Captura: %file%
    GoSub>Continuar,Message
Endif

Let>LOCALVARS=0
END>Captura_Haystack

I don't think you can directly split the lines as you suggest so better to build it up step by step instead. Personally, for calling the SRT I would probably just add a couple of lines assigning the long variables to shorter ones and then pass the shorter ones to the SRT (you can then hide the lines within CODEBLOCK> ... ENDCODEBLOCK>)

(As an aside, there is a way you can split and add the lines yourself (see below). When you run the program the full names will be inserted on one line but when you write it you can have it on split lines. Would require a couple of extra lines.)

Code: Select all

/*
Captura_Haystack:
GoSub>Captura_Haystack,_
BB_PANEL_DER_INI_X,_
BB_PANEL_DER_INI_Y,_
BB_PANEL_DER_FIN_X,_
BB_PANEL_DER_FIN_Y,_
temp_Captura_Verificable
*/

LabelToVar>Captura_Haystack,Captura_Haystack
RegEx>(?m-s)_\R,Captura_Haystack,0,m,nm,1,,Captura_Haystack
IncludeFromVar>Captura_Haystack

pantik
Junior Coder
Posts: 45
Joined: Sun Dec 13, 2009 5:52 pm

Re: How to write code in several lines

Post by pantik » Mon Oct 05, 2015 5:49 pm

Ok , thank you so much for that info.

User avatar
Marcus Tettmar
Site Admin
Posts: 7391
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: How to write code in several lines

Post by Marcus Tettmar » Tue Oct 06, 2015 9:30 am

There's no line continuation character. But there is always word wrap ;-)
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Re: How to write code in several lines

Post by armsys » Tue Oct 06, 2015 9:44 am

Hi Marcus,
Thank you for showing us the practical use of IncludeFromVar.

pantik
Junior Coder
Posts: 45
Joined: Sun Dec 13, 2009 5:52 pm

Re: How to write code in several lines

Post by pantik » Tue Oct 06, 2015 12:49 pm

Wrap is ok but it creates new memory spaces increasing the memory used by the program , right?

User avatar
Marcus Tettmar
Site Admin
Posts: 7391
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: How to write code in several lines

Post by Marcus Tettmar » Tue Oct 06, 2015 1:06 pm

pantik wrote:Wrap is ok but it creates new memory spaces increasing the memory used by the program , right?
Err, why?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

pantik
Junior Coder
Posts: 45
Joined: Sun Dec 13, 2009 5:52 pm

Re: How to write code in several lines

Post by pantik » Tue Oct 06, 2015 1:24 pm

becasue you create new variables... i dont know just asking...

User avatar
Marcus Tettmar
Site Admin
Posts: 7391
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: How to write code in several lines

Post by Marcus Tettmar » Tue Oct 06, 2015 1:25 pm

Word wrap just wraps the lines in the editor. Nothing to do with variables.

Under the editor select Edit/Word Wrap.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

pantik
Junior Coder
Posts: 45
Joined: Sun Dec 13, 2009 5:52 pm

Re: How to write code in several lines

Post by pantik » Tue Oct 06, 2015 1:33 pm

Ahh!! Ok. I did not know this feature. Well that is what i was looking for.Thanks Marcus

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts