 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Makinus
Joined: 24 Jun 2008 Posts: 3
|
Posted: Tue Jun 24, 2008 12:31 pm Post subject: Newbie problem with variables/GUI |
|
|
It´s probably a very easy step, but i´m stumped... i just downloaded Autohotkey and i´m creating scripts, and i simply can´t find the answer to my problem:
I wish to create a GUI that shows a Button and a Text control... when the script starts the text control should be empty, then the user would click the button and the script would ask him to select a file, then, after selecting the file, the Text control should display in the GUI the filename with complete path selected... here is my code, what i´m doing wrong?:
| Code: | #r::
file1 := "nothing"
Gui, Add, Button,,File1
Gui, Add, Text, %file1%
Gui, Show
Return
ButtonFile1:
FileSelectFile, file1
FileGetSize, file1size, %file1%
MsgBox, %file1%
MsgBox, %file1size%
Return |
Thanks! |
|
| Back to top |
|
 |
Klaus
Joined: 12 May 2005 Posts: 205 Location: Münster, Germany
|
Posted: Tue Jun 24, 2008 1:07 pm Post subject: |
|
|
Hi, Makinus,
just two corrections:
| Code: | file1 := "nothing"
Gui, Add, Button,,File1
Gui, Add, Text, w180 vMyText, %file1% ; ===> assign a variable to the control and give a little width to it
Gui, Show, w200 h50
Return
ButtonFile1:
FileSelectFile, file1
FileGetSize, file1size, %file1%
MsgBox, %file1%
MsgBox, %file1size%
GuiControl,, MyText, %file1% ; ===> put the name of the selected file into the text control
Return
|
Hope I could help,
Klaus |
|
| Back to top |
|
 |
Icarus
Joined: 24 Nov 2005 Posts: 507
|
Posted: Tue Jun 24, 2008 1:16 pm Post subject: |
|
|
First of all, you have a problem here:
Gui, Add, Text, %file1%
The parameter right after "Text" should be options for the gui control.
You probably wanted to do
Gui, Add, Text,, %file1%
The more important issue, is that the fact that you just assign a variable to a GUI control does not magically update the GUI whenever the variable is updated.
You must specifically change the GUI control, using a command called GuiControl.
See this example.
| Code: |
#SingleInstance Force
Gui, Add, Button, w400 gSelectFile, Please Select a File
Gui, Add, Text , wp vFileName , No File Selected
Gui, Show
Return
SelectFile:
FileSelectFile, File1
If ErrorLevel ; If the user cancelled, do nothing
Return
FileGetSize, File1Size, %File1%
; Must use this to change GUI control
GuiControl,,FileName,%File1% (%File1Size% bytes)
Return
|
hth
EDIT:
Klaus beat me to the punch  |
|
| Back to top |
|
 |
Makinus
Joined: 24 Jun 2008 Posts: 3
|
Posted: Tue Jun 24, 2008 7:30 pm Post subject: |
|
|
Thanks! that was exacly what i needed....
Now i´m with another hurdle (pelase be patient with a newbie!): how do i make a button that calls a function when clicked? I already know how to call a label/subroutine, but how do i make a button call a function when pressed? thanks... |
|
| Back to top |
|
 |
Krogdor
Joined: 18 Apr 2008 Posts: 1145 Location: The Interwebs
|
Posted: Tue Jun 24, 2008 7:33 pm Post subject: |
|
|
You just have to add a subroutine with a function in the subroutine. Ex:
| Code: | Gui, Add, Button, gFunctions, Click me!
Gui, Show
Return
Functions:
SomeFunction() |
|
|
| Back to top |
|
 |
Icarus
Joined: 24 Nov 2005 Posts: 507
|
Posted: Tue Jun 24, 2008 7:46 pm Post subject: |
|
|
| Makinus wrote: | | Now i´m with another hurdle (pelase be patient with a newbie!): how do i make a button that calls a function when clicked? |
Makinus,
Tons of patience on this forum, do not hesitate to ask.
This issue that you mentioned (and was solved in the post above me) also threw me off when I started - buttons should be able to call functions, but they cant.
In fact, the entire GUI thing in AHK may become problematic in more elaborate scripts, since all variables are global and such. But it does the job, and does it well.
If you do not have time to go through the entire help file, I at least strongly suggest you go through Gui, Add and GuiControl.
These are important sections for your objective and you may find some things you did not know possible, and that can make your life easier. |
|
| Back to top |
|
 |
Makinus
Joined: 24 Jun 2008 Posts: 3
|
Posted: Wed Jun 25, 2008 2:46 pm Post subject: |
|
|
I´m still with problems in variables and i did read the entire help file and could not find what i´m doing wrong...
First the code (this one is big):
| Code: | Gui, Add, Button, x16 y37 w50 h20 gFindFile1, Arquivo
Gui, Add, Text, x76 y37 w540 h20 vText1,
Gui, Add, DropDownList, x16 y67 w190 h20 r7 vtipo1 AltSubmit, Contestação|Outros|Petição|Petição Inicial|Procuração|Substabelecimento|Tomada de Termo
Gui, Add, Edit, x216 y67 w400 h20 VDesc1,
Gui, Add, Button, x16 y527 w100 h30 genvia, Enviar
Gui, Add, Text, x150 y545, Tempo estimado para envio:
Gui, Add, Text, x300 y545 vtempototal w300,
Gui, Show, x131 y91 h587 w632, New GUI Window
Return
GuiClose:
ExitApp
FindFile1:
FileSelectFile, file1
FileGetSize, file1size, %file1%
time1 := Round(file1size/20)
tempototal := Round((time1)/1000*1.2)" Segundos"
GuiControl,, text1, %file1%
GuiControl,, tempototal, %tempototal%
return
envia:
ycoor := 205+(tipo1*11)
WinActivate, Projudi - Processo Virtual - Mozilla Firefox
MouseClick, left, 316, 393
Sleep, 100
MouseClick, Left, 316, ycoor
Sleep, 100
if (tipo1=2)
{
MouseClick, left, 345, 393
Sleep, 100
Send, %desc1%
}
MouseClick, left, 363, 436
Sleep, 100
WinWait, Enviar arquivo,
IfWinNotActive, Enviar arquivo, , WinActivate, Enviar arquivo,
WinWaitActive, Enviar arquivo,
Send, %file1%
Send, {Enter}
Sleep 1000
WinActivate, Projudi
MouseClick, left, 470, 491
Sleep %time1%
return |
This is part of the code of a program i´m creating in autohotkey to upload files in a webpage, the webpage only allows the upload of 1 file at a time and the program would get the location, type, and description of each file and upload each file to the webpage, wait the file to be uploaded, then sendo the next file.
Now, for every file sent i must select in the webpage the type and location of the file and if (and only if) the type is "Outros" (others in portuguese) the program should send the description to the webpage.
The thing is, when selecting the type of the file on the webpage i must click a button that shows a dropdownlist for me to choos, and every iten is on the y position 205+(type*11)... i.e. "Outros" being the 2nd item would be 205+(2*11) that results in 227 as the y coord...
The problem is, when i click the button that directs to the label "enviar:" the variables appear to become blank... so the calculating of the y coordinate goes wrong...
btw: thanks for all the help! its hard to find a forum with the kind of patience with newbies that you are all displaying... that really gives an incentive to learn more... |
|
| Back to top |
|
 |
Icarus
Joined: 24 Nov 2005 Posts: 507
|
Posted: Wed Jun 25, 2008 3:11 pm Post subject: |
|
|
From a quick look, it seems like you are missing something simple.
Put this as the first thing in your envia routine.
You will need to use this whenever you want the variables used in the GUI to receive the values that were inputted by the user.
Also, this is not critical, but you should also have it - add Return after your GuiClose label
| Code: | GuiClose:
ExitApp
Return |
I did not dig too deep into your script, so tell me if this does not solve it.
EDIT:
One small suggestion for your future help requests:
It will be easy to help if the scripts that you are posting are as small as possible, and only demonstrate the problem.
For example, your entire problem could have been summarized like so:
| Code: |
Gui Add, Edit, w100 vTheText, Hello
Gui Add, Button, wp gDoIt, Submit
Gui, Show
Return
DoIt:
;Gui Submit, NoHide ; Uncomment to solve
msgbox TheText variable is [%TheText%] ; Variable is empty
Return
|
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|