Subroutine works only once.

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
psiquetp
Junior Coder
Posts: 25
Joined: Tue Jul 17, 2018 7:56 pm

Subroutine works only once.

Post by psiquetp » Tue Jul 17, 2018 8:03 pm

My function works the first time I call it, but the second time it does not.
The order of the calls is not important, if I call first for the password the password will work and the user will not be clicked, otherwise the user will be clicked and the password will not.

Code: Select all

// COMPILE_OPTS|C:\MacroHelper\MyMacro.exe|C:\MacroHelper\MyExe.ico|CONSOLE=0|INCLUDES=1||RUNTIMES=1|BMPS=1
//Set IGNORESPACES to 1 to force script interpreter to ignore spaces.
//If using IGNORESPACES quote strings in {" ... "}
//Let>IGNORESPACES=1

Dim IMAGE_NAME
Dim FILE_LINE_INDEX

//Subroutine to Add Text.
SRT>ClickAndWrite
  //Screen 1
  //Click The text box
  FindImagePos>%IMAGE_NAME%,SCREEN,0.7,1,XArr,YArr,NumFound,CCOEFF
  If>NumFound>0
    MouseMove>XArr_0,YArr_0
    LClick
  Endif
  If>NumFound=0
    MessageModal>The image was not found. %IMAGE_NAME%
  Endif

  Wait>1
  
  //Write the Text
  ReadLn>C:\MacroHelper\execution.txt,%FILE_LINE_INDEX%,Text_To_Write
  VBEval>right("%Text_To_Write%",len("%Text_To_Write%")-InStr("%Text_To_Write%","=")),Text_To_Write
  SendText>Text_To_Write
END>ClickAndWrite

//Click User ID
Let>%IMAGE_NAME%=C:\MacroHelper\images_steps\01_userame.png
Let>%FILE_LINE_INDEX%=1
GoSub>ClickAndWrite

//Click Password
Let>%IMAGE_NAME%=C:\MacroHelper\images_steps\02_password.png
Let>%FILE_LINE_INDEX%=2
GoSub>ClickAndWrite
Also, is there another way to pass variables than to declare them global?

Thank you!
Carlos Alberto
Last edited by psiquetp on Wed Jul 18, 2018 7:56 pm, edited 1 time in total.

User avatar
Grovkillen
Automation Wizard
Posts: 1009
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Subroutine works only once.

Post by Grovkillen » Wed Jul 18, 2018 4:33 pm

Your Let>%VAR_NAME%=... is not what you think. Remove the two % in the Let> statements and it'll work just fine.
Let>ME=%Script%

Running: 15.0.24
version history

psiquetp
Junior Coder
Posts: 25
Joined: Tue Jul 17, 2018 7:56 pm

Re: Subroutine works only once.

Post by psiquetp » Wed Jul 18, 2018 7:55 pm

Thank you very much Grovkillen, it worked like a charm. Can you provide a little insight into why? is the % character for deasignation?

Also, is there another construct I can use that is more like a Function ... something like GoFunc>FuncName,Param,Param2
?

Thank you!

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

Re: Subroutine works only once.

Post by Marcus Tettmar » Wed Jul 18, 2018 9:06 pm

% .. % means "get the value of". So if you have it on the left of an assignation you are assigning the new value to the VALUE of the thing you specify. Consider the following:

Let>a=fred
Let>%a%=sally

This will be doing the same as:

Let>fred=sally

Which is probably NOT what you mean. It COULD be what you want and has uses at times, e.g. when assigning to array type variables:

Let>array_%k%=sally

But if you meant to give 'a' a new value then just do:

Let>a=sally

Otherwise you'll actually be assigning the new value to the VALUE of a, rather than a itself.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

psiquetp
Junior Coder
Posts: 25
Joined: Tue Jul 17, 2018 7:56 pm

Re: Subroutine works only once.

Post by psiquetp » Wed Jul 18, 2018 9:47 pm

Thank you so much to both.

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