Jump to content

How to structure code? (New to AutoIT)


Recommended Posts

Hi guys,

I'm absolutly new to AutoIT and programming at all. Nevertheless I find it pretty exiting to solve a repetetive problem by coding a script.

Unfortunately, I have just reached a point where I don't know what to do.

The aim of the program is to perform mouse clicks on a certain website fully automatically at certain times.

The script should be executed after the start of a virtual machine and should be structured as follows (please see figure):
1. Examine, if it shall either register or deregister, depending on the day of the week and the time of day, i.e. there are two different procedures
2. Establishing a VPN tunnel to a specific network (via Cisco Anyconnect Secure Mobility Client)
3. Carry out registration or deregistration (after previously examined)
4. End VPN
5. Shut down the VM

SVGGraph-1.png

As I understand, the code runs from the first line. Unfortunately, I don't quite know how to structure it for the script to work.

I thought about packing individual program components into functions and then only executing them when they were needed. Some functions like the VPN should always be carried out, some only if they meet my conditions. Unfortunately, the code has not yet worked.

AutoItSetOption('MouseCoordMode', 0)
Global $WDAY, $HOUR
$WDAY = @WDAY
$HOUR= @HOUR


If $WDAY = 3 OR 4 Then
   examination()
EndIf

Func examination()
   If $HOUR = 07 or 08 Then
      registration()
   ElseIf $HOUR = 12 or 13 Then
      deregistration()
   EndIf
EndFunc

Func registration()
   ShellExecute('C:\Program Files\Mozilla Firefox\firefox.exe', '-new-window website.com')
   WinWait('website title')
   WinActivate('website title')
   Sleep (3000)
   MouseClick('primary', 135, 342, 1, 0)
   Send('username')
   MouseClick('primary', 138, 377, 1, 0)
   Send('password')
   MouseClick('primary', 82, 408, 1, 0)
   Sleep (3000)
   MouseClick('primary', 93, 591, 1, 0)
   Sleep (3000)
   MouseClick('primary', 652, 520, 1, 0)
   Sleep (3000)
   MouseClick('primary', 728, 625, 1, 0)
   Sleep (3000)
   MouseClick('primary', 92, 246, 1, 0)
   MouseClick('primary', 1006, 21, 1, 0)
EndFunc

Func deregistration()
   MsgBox(0,0,0)
EndFunc

(MsgBox is just for testing, if my approach works out..., but it didn't)

Please rate my approach. I would be very happy to receive a hint to solve the problem. Thank you in advance for your support.

Greetings
Fazer

 

 

Link to comment
Share on other sites

Your if are badly formatted.  It should be :

If $WDAY = 3 OR $WDAY = 4 Then

Also @HOUR returns a string not a numeric.

Finally you should consider using a Web Browser UDF, instead of mouseClicks (WebDriver for Firefox).

Edited by Nine
Link to comment
Share on other sites

19 hours ago, Nine said:

Your if are badly formatted.  It should be :

If $WDAY = 3 OR $WDAY = 4 Then

Also @HOUR returns a string not a numeric.

Finally you should consider using a Web Browser UDF, instead of mouseClicks (WebDriver for Firefox).

It's working now.

Thank you @Nine for this great advice! Really appreciate it!

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