Sign in to follow this  
Followers 0
MarioTester

How to edit source code using Gui?

6 posts in this topic

So, Hey!

I already posted here explaining as AutoIt is my first language and seriously, I love it! I'm doing scripts for all kind of things, its really great. Well, anyways, in this particular script I'm doing, while it works very well, I would like to add a feature that I have no idea on how to do, I have already been through help file without any luck, well, let me explain.

My basic Idea is, the whole script works perfectly, he needs only two variables to work, these variables are unique to eachother and change at every run. The variable 1 is a link, the variable 2 is the message that is supposed to be written in said link.

I.e:

First run: Go to www.google.com, write "potato", search

Second run: Go to www.bing.com, write "power ranger", search

Ok so, this is the basic idea, what I want to do though is, through a GUI, be able to add both variables, so that would be kind of writting something in the Gui, clicking "Add" and editing the source code forever, with those new two variables. That's what I dont even know how to begin doing. Anyways, let me show you the script:

HotKeySet( "{END}", "Terminate")
Global $OpenAddress
Global $Answer
Global $Count = 0;
Global $Total = 17;

While $Count < $total
Site()
Tooltip( $Count&"/"&$Total,0,0,"Actual / Total")
WEnd

While $Count = $Total
Tooltip( "Done a total of "&$total,0,0,"Im finished.")
sleep(100)
WEnd

Func SetVariables();The threads and answers
Select
  Case $Count = 0
   $OpenAddress ="http://censored.com"
   $Answer = "Anyword."
  Case $Count = 1
   $OpenAddress = "http://censored1.com"
   $Answer = "Otherword."
  Case $Count = 2
   $OpenAddress = "http://censored3.com"
   $Answer = "Anotherword"
  Case Else
MsgBox(0, "Ops", "That isn't supposed to happen, dude")
EndSelect
EndFunc

Func Site()
ShellExecute("opera.exe", "", "C:\Program Files\Opera\", "open"); When I do this, browser opens a new tab
WinWaitActive("Speed Dial - Opera")
SetVariables()
Send($OpenAddress & "{enter}")
Sleep(500)
Do
$loaded = Pixelsearch(1036, 247, 1038, 249, 0x0B2943, 10);way to check page loaded
Sleep(200)
Until IsArray($loaded) = 1
MouseClick("left", 1059, 247, 1)
Do
$loaded2= PixelSearch(155, 337, 157, 339, 0xFFE622, 10);Checks if second page loaded
sleep(200)
Until IsArray($loaded2) = 1
send("{Tab}")
sleep(50)
Send($Answer&"{tab}"&"{enter}")
$Count = $Count + 1
sleep(50)
return "done"
EndFunc
Func Terminate() ;This is a function and doesn't actually run unless you tell it to. For example
Exit
EndFunc   ;==>Terminate

So anyways, This is the basic idea, the actual "setvariables()" include 18 "$openaddress" and "$Answer", going to case 0 until case 18, but It would be pointless to post all of then, since 3 are enough to give the idea. Right now, when I want to add variables, I manually go there and add cases in source code. I know there's no GUI whatsoever in this script, It's because creating the GUI would be pointless without knowing how to make the whole "add new variables" part.

Also, I believe that I should use "Switch" instead of "Select". I'm going to do that.

Thanks in advance!


TL;DR I'm new to autoit or any programming language whatsoever.

Share this post


Link to post
Share on other sites



MarioTester, As I don't have opera I can't really test this, but this might work.

HotKeySet("{END}", "Terminate")
Global $OpenAddress
Global $Answer
Global $Count = 0;
Global $Total = 17;

HotKeySet("^!n", "Add_New");ctrl+shift+n

While 1
     If $Count < $Total Then
          Site()
          ToolTip($Count & "/" & $Total, 0, 0, "Actual / Total")
     Else
          ToolTip("Done a total of " & $Total, 0, 0, "Im finished.")
          Sleep(100)
     EndIf
WEnd

Func Add_New()
     $OpenAddress = InputBox('New Link', 'Add New Link')
     $Answer = InputBox('New Answer', 'Add New Answer')
     $Total += 1
EndFunc

Func SetVariables();The threads and answers
     Select
          Case $Count = 0
               $OpenAddress = "http://censored.com"
               $Answer = "Anyword."
          Case $Count = 1
               $OpenAddress = "http://censored1.com"
               $Answer = "Otherword."
          Case $Count = 2
               $OpenAddress = "http://censored3.com"
               $Answer = "Anotherword"
          Case Else
               MsgBox(0, "Ops", "That isn't supposed to happen, dude")
     EndSelect
EndFunc   ;==>SetVariables

Func Site()
     ShellExecute("opera.exe", "", "C:\Program Files\Opera\", "open"); When I do this, browser opens a new tab
     WinWaitActive("Speed Dial - Opera")
     SetVariables()
     Send($OpenAddress & "{enter}")
     Sleep(500)
     Do
          $loaded = PixelSearch(1036, 247, 1038, 249, 0x0B2943, 10);way to check page loaded
          Sleep(200)
     Until IsArray($loaded) = 1
     MouseClick("left", 1059, 247, 1)
     Do
          $loaded2 = PixelSearch(155, 337, 157, 339, 0xFFE622, 10);Checks if second page loaded
          Sleep(200)
     Until IsArray($loaded2) = 1
     Send("{Tab}")
     Sleep(50)
     Send($Answer & "{tab}" & "{enter}")
     $Count = $Count + 1
     Sleep(50)
     Return "done"
EndFunc   ;==>Site

Func Terminate() ;This is a function and doesn't actually run unless you tell it to. For example
     Exit
EndFunc   ;==>Terminate

Share this post


Link to post
Share on other sites

First of all, thanks for quick answer Beegee =) Im not sure I got your suggestion wrong, but I fail to understand how this would solve the problem. Maybe I'm missing something, but you see, the point is, I want to somehow assign two new values to two variables for a certain case +=1, however, these new two values I add should be able to be there forever, whenever I executed the script again they would already be there, instead of me having to input them every time.


TL;DR I'm new to autoit or any programming language whatsoever.

Share this post


Link to post
Share on other sites

Oh I see, my mistake. Well you can't modify the source of your code while its running, but what you could do is create a simple .ini file that has all your links and answers in it. Then when your script starts read in all the links from that file. When you have new one write it to the file. This way it would be saved permanently. Look at functions IniRead, IniWrite etc.

Share this post


Link to post
Share on other sites

I can write INIS!? THAT'S GREAT!!! That's definitely going to solve my problem thanks a lot Beege o/


TL;DR I'm new to autoit or any programming language whatsoever.

Share this post


Link to post
Share on other sites

Your very welcome :)

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