AutoHotkey Community

It is currently May 26th, 2012, 7:11 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: May 22nd, 2008, 1:46 am 
Offline

Joined: April 29th, 2008, 11:14 pm
Posts: 20
Hi people!!

I have the following script to automate an formulary fill process. This code is not actually de aplication itself but contains some samples of what the application is supposed to do.

Code:
;----------------manufacturer selection variables-------------

BrandChoice1 = |LG|Samsung|Phillips
BrandChoice2 = |Ford|Fiat|GM
BrandChoice3 = |HP|IBM|ASUS

;----------------tv screen size selection variables-----------

TVChoice1 = |19`"|21`"|29`"
TVChoice2 = |14`"|15`"|19`"
TVChoice3 = |29`"|32`"|40`"

;----------------car model selection variables----------------

CarChoice1 = |Fusion|Ka|Ecosport
CarChoice2 = |Uno|Punto|Idea
CarChoice3 = |Astra|Meriva|Vectra

;----------------computer model selection variables----------------

ComputerChoice1 = |Compaq|Pavilion|Pavilion Slimline
ComputerChoice2 = |Lenovo 3010|Lenovo 3020|Lenovo 4000
ComputerChoice3 = |Notebook W2V|Notebook W2JC|Notebook W2P

;----------------location selection variables----------------

LOCATION = |SAO PAULO|NEW YORK|TOKIO

;----------------GUI------------------------------------------

Gui, Add, Text, x21 y9 w200 h16, Please select an item from the Wish List:
Gui, Add, ListBox, x21 y25 w200 h90 vProduct gWishList AltSubmit, Digital TV|Car|Computer ; select product type
;
Gui, Add, Text, x21 y114 w200 h16, Select a manufacturer:
Gui, Add, DropDownList, x21 y130 w200 vManufacturer gManufacturer AltSubmit, ; select manufacturer
;
Gui, Add, Text, x21 y159 w200 h16, Select a model:
Gui, Add, DropDownList, x21 y175 w200 vMake , ; select model
;
Gui, Add, Button, x21 y207 w100 h30 , Submit
Gui, Show, w242 h255
return


WishList:

Gui, Submit, NoHide
Choice := BrandChoice%product% ; establishes the manufacturer dropdown
GuiControl, , manufacturer, %choice% ; puts that dropdown in place
GuiControl, , Make, | ; empties the model dropdown in case it contains data
return

Manufacturer:

Gui, Submit, NoHide
if Product = 1 ; will run if Digital TV was chosen
{
  Model := TVChoice%Manufacturer%
  GuiControl, , Make, %Model%
  return
}
else if Product = 2 ; will run if Car was chosen
{
  Model := CarChoice%Manufacturer%
  GuiControl, , Make, %Model%
  return
}
else if Product = 3 ; will run if Computer was chosen
{
  Model := ComputerChoice%Manufacturer%
  GuiControl, , Make, %Model%
  return
}

ButtonSubmit:
Gui, Submit, NoHide

if Make = Lenovo 4000
{
Gosub  Lenovo4000
  Return
 }
 else if Make = Lenovo 3020
{
MsgBox, Lenovo 3020 has chosen!!!
  Return
}
  else if Make = Lenovo 3010
{
MsgBox, Lenovo 3010 has chosen!!!
  Return
}

Lenovo4000:

Gui, 2:Add, Text, x26 y27 w100 h20 , Name
Gui, 2:Add, Edit, x26 y57 w250 h20 vName ,

Gui, 2:Add, Text, x26 y87 w100 h20 , Mail Address
Gui, 2:Add, Edit, x26 y117 w250 h20 vMail ,

Gui, 2:Add, Text, x26 y147 w100 h20 , Location
Gui, 2:Add, DropDownList, x26 y177 w250 vLocationchoice , %LOCATION%

Gui, 2:Add, Button, x26 y227 w100 h30 , Submit
Gui, 2:Show, x300 y278 h277 w305, Form Data

Return

2ButtonSubmit:
Gui, Submit, NoHide

WinActivate ahk_class Notepad
SendInput %Locationchoice%{Enter}
SendInput %Name%{Enter}
SendInput %Mail% {Enter}


MsgBox, Personal data Submited!!!!
return
 
GuiEscape:
GuiClose:
ExitApp


All functions are working correctly. The trouble is occurring when i do the following:

choose the options COMPUTER>IBM>LENOVO 4000 than a second GUI appear. Inserting data and submitting to fill a notepad file is ok too. But when i close the second GUI and try to reselect the same path (COMPUTER>IBM>LENOVO 400) again an error message appears: The same variable cannot be used.... Specifically vName.

What am i doin wrong? Is there a way to fix it?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 22nd, 2008, 2:01 am 
Offline

Joined: April 4th, 2008, 8:15 pm
Posts: 538
Location: Canada
Code:

;----------------manufacturer selection variables-------------

BrandChoice1 = |LG|Samsung|Phillips
BrandChoice2 = |Ford|Fiat|GM
BrandChoice3 = |HP|IBM|ASUS

;----------------tv screen size selection variables-----------

TVChoice1 = |19`"|21`"|29`"
TVChoice2 = |14`"|15`"|19`"
TVChoice3 = |29`"|32`"|40`"

;----------------car model selection variables----------------

CarChoice1 = |Fusion|Ka|Ecosport
CarChoice2 = |Uno|Punto|Idea
CarChoice3 = |Astra|Meriva|Vectra

;----------------computer model selection variables----------------

ComputerChoice1 = |Compaq|Pavilion|Pavilion Slimline
ComputerChoice2 = |Lenovo 3010|Lenovo 3020|Lenovo 4000
ComputerChoice3 = |Notebook W2V|Notebook W2JC|Notebook W2P

;----------------location selection variables----------------

LOCATION = |SAO PAULO|NEW YORK|TOKIO

;----------------GUI------------------------------------------

Gui, Add, Text, x21 y9 w200 h16, Please select an item from the Wish List:
Gui, Add, ListBox, x21 y25 w200 h90 vProduct gWishList AltSubmit, Digital TV|Car|Computer ; select product type
;
Gui, Add, Text, x21 y114 w200 h16, Select a manufacturer:
Gui, Add, DropDownList, x21 y130 w200 vManufacturer gManufacturer AltSubmit, ; select manufacturer
;
Gui, Add, Text, x21 y159 w200 h16, Select a model:
Gui, Add, DropDownList, x21 y175 w200 vMake , ; select model
;
Gui, Add, Button, x21 y207 w100 h30 , Submit
Gui, Show, w242 h255
return


WishList:

Gui, Submit, NoHide
Choice := BrandChoice%product% ; establishes the manufacturer dropdown
GuiControl, , manufacturer, %choice% ; puts that dropdown in place
GuiControl, , Make, | ; empties the model dropdown in case it contains data
return

Manufacturer:

Gui, Submit, NoHide
if Product = 1 ; will run if Digital TV was chosen
{
  Model := TVChoice%Manufacturer%
  GuiControl, , Make, %Model%
  return
}
else if Product = 2 ; will run if Car was chosen
{
  Model := CarChoice%Manufacturer%
  GuiControl, , Make, %Model%
  return
}
else if Product = 3 ; will run if Computer was chosen
{
  Model := ComputerChoice%Manufacturer%
  GuiControl, , Make, %Model%
  return
}

ButtonSubmit:
Gui, Submit, NoHide

if Make = Lenovo 4000
{
Gosub  Lenovo4000
  Return
 }
 else if Make = Lenovo 3020
{
MsgBox, Lenovo 3020 has chosen!!!
  Return
}
  else if Make = Lenovo 3010
{
MsgBox, Lenovo 3010 has chosen!!!
  Return
}

Lenovo4000:

Gui, 2:Add, Text, x26 y27 w100 h20 , Name
Gui, 2:Add, Edit, x26 y57 w250 h20 vName ,

Gui, 2:Add, Text, x26 y87 w100 h20 , Mail Address
Gui, 2:Add, Edit, x26 y117 w250 h20 vMail ,

Gui, 2:Add, Text, x26 y147 w100 h20 , Location
Gui, 2:Add, DropDownList, x26 y177 w250 vLocationchoice , %LOCATION%

Gui, 2:Add, Button, x26 y227 w100 h30 , Submit
Gui, 2:Show, x300 y278 h277 w305, Form Data

Return

2ButtonSubmit:
Gui, Submit, NoHide

WinActivate ahk_class Notepad
SendInput %Locationchoice%{Enter}
SendInput %Name%{Enter}
SendInput %Mail% {Enter}

Gui, Destroy

MsgBox, Personal data Submited!!!!
return

2GuiClose:
Gui, Destroy
return

GuiEscape:
GuiClose:
ExitApp


Should work :o


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 22nd, 2008, 2:07 am 
Offline

Joined: April 29th, 2008, 11:14 pm
Posts: 20
Tnx PurloinedHeart!!!

It worked indeed. Would you please explain the lines you've added to the code?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 22nd, 2008, 2:12 am 
Offline

Joined: April 4th, 2008, 8:15 pm
Posts: 538
Location: Canada
(From the helpfile, I think it describes it the best)
Quote:
Gui, Destroy
Removes the window (if it exists) and all its controls, freeing the corresponding memory and system resources. If the script later recreates the window, all of the window's properties such as color and font will start off at their defaults (as though the window never existed). If Gui Destroy is not used, all GUI windows are automatically destroyed when the script exits.


I placed the Gui, Destroy right after you were done working with the variables, so they don't have values after the operation is complete.

2GuiClose is the same as GuiClose, except for the second Gui window, since the user closed the window before they submitted anything, Gui, Destroy makes the variables blank again.

Hope I explaned it properly :?


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google Feedfetcher, kkkddd1 and 65 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group